The TCP/IP Routing Mantra
Here is the basic algorithm used to route any packet in TCP/IP.
Any time you have routing difficulties, the answer will be found in
chanting this routing mantra until you reach routing enlightenment.
- Is the destination address of this packet associated with one
of the interfaces directly known to me? In other words, "is this
packet supposed to go somewhere inside this computer?" This
covers the cases which arise when you do something like try to
telnet to your own system or use lynx to look at your own web page.
If the answer to this question is no, we fall on through to the second
step:
- Is the destination address of this packet in the same class C
block as an ethernet interface that I have? If not, we will
fall on to the next step. If so, there is a secondary question
involved: the question of ARP. ARP, or "Address Resoultion Protocol",
is a broadcast mechanism that TCP/IP uses to translate an IP address
to an ethernet address. See, on a LAN, your ethernet card needs to
use ethernet addresses to send packets to another ethernet card.
If TCP/IP lacks an "ARP Entry" for the destination address, it's going
to broadcast an ARP request on the ethernet. The request essentially
means "which one of you ethernet cards out there should I send this
packet to?". The existing ARP entries can be displayed at any time
by using the SHOW ARP command. If TCP/IP DOES CURRENTLY HAVE an
ARP entry, it will use that. The ARP entry can override the assumption
that this packet should go out the ethernet at all. This override
mechanism is very important, as we shall see when we read more about
ARP on different walls of the cave.
- Since the destination IP address is not associated with one of
my own interfaces, and it's not in my network, I'm going to have to consult
the routing tables. The more specific routing entries are used in
preference to the more general ones. For example, if the
destination address is 204.181.142.11, then a routing entry specifically
telling me how to get to 204.181.142.11 takes precedence over one which
tells me how to get to 204.181.142.0 (the 0 is a wildcard construct),
which in turn takes precedence over the match-all routing entry 0.0.0.0.
There is a SHOW ROUTE command which you can use to display the
existing routing tables.
The routing mantra is so imporant that we are going to summarize what
we have just said, at the risk of repeating ourselves:
- Check to see if we own the interface.
- Check for a network match. If found, either use an existing
ARP entry or -- if there is none -- try to get one.
- Resort to the routing tables.