Introduction to TCP/IP and routing : Routing : Where do you route ?
Previous: When do you route ?
Next: Introduction to TCP/IP and routing

2.3. Where do you route ?

Once you have determined that the host is not directly reachable, a decision has to be made of where to send the packet.

On every host, a routing table exists which contains at least a route to the local network (implicit).

This is a routing table as seen on a UNIX machine, shown by the command netstat -rn:

  Internet:
  Destination        Gateway            Flags     Refs     Use     Netif Expire
  default            192.168.1.1        UGSc       22      375      ed1
  127.0.0.1          127.0.0.1          UH         11   513997      lo0
  192.168.1          link#1             UC          0        0      ed1
  192.168.1.1        0:20:af:4:fc:6a    UHLW       30 10960470      ed1    969
  192.168.1.2        0:20:18:28:5a:23   UHLW        0    13746      lo0
  192.168.1.10       0:0:c:92:ef:5      UHLW        1        1      ed1   1197
  192.168.1.12       0:10:7b:30:23:81   UHLW        0     2030      ed1    914
  192.168.100        192.168.1.10       UGSc        0        0      ed1

For each destination a gateway, which must be directly reachable, is listed. This gateway is called the next hop in the path, and at any given moment, the router/host knows only of the next hop, and not the entire path (since this one can change).

To the right is also indicated the interface (Netif) through which that destination can be reached.

Destinations can both be networks and hosts.

As we can see, directly reachable hosts appear with their MAC/LCC address, including the host's own local address.

The first destination, default, is a special route, called a default route: this route can be added if there is only one router, or gateway, through which to "leave" the network.

The local network is indicated as being directly reachable through link#1, as are the hosts 192.168.1.1, .10 and .12 -- they are all on the same Ethernet network.

A manual (static) route has been added for network 192.168.100 /24, with a gateway of 192.168.1.10. This is read as:

Network 192.168.100.0 /24 is reachable through the gateway 192.168.1.10

For each packet sent, a routing decision is made by looking up into the routing table:

  1. Is the destination host a directly reachable/local host ?

    If yes, then send the packet to the local address and stop, else...

  2. Does there exist a defined route the destination of which is the destination host's network ?

    If yes, then send the packet to the next hop (the gateway), and stop, else...

  3. Does there exist a default route to which to send all unknown destination addresses ?

    If yes, then send the packet to it, and stop, else...

  4. Drop packet.


Introduction to TCP/IP and routing : Routing : Where do you route ?
Previous: When do you route ?
Next: Introduction to TCP/IP and routing