G22.2262
October 8, 1998

IP Routing

Please read chapter 8 to help understand this material.
Also, please read sections 10.6 through 10.14 to help understand subnet masks.
 

Note:  for most machines, a single default entry is all you need.
For example:

        A    B     C   D      E      F    G     H
        |       |       |   / \       |       |       |      |
      --------------   ---------------------
 
Machines A, B, C, E, F, G, and H all have a default route in their routing table, specifying D as the default router (A, B, and C specify the first interface of D. Machines E, F, G, and H specify the second interface of D).

Each entry in the routing table contains the following:
    1.  A destination IP address.  This can be a full host address of a network address.
    2.  The IP address of the router, or your IP address. If your IP address is specified, it means the destination is on a directly-connected network.
    3.  Flags.  For example, one flag indicates whether the first entry is a host or a network.
    4.  Specification of which interface to use.
 

Before IP attempts to do any routing, it ill do the following:
    1.  Get the destination address of a packet
    2.  Get the network number of the destination (note, subnet masks must be used in getting the network number).
    3.  Of course, if the destination network is a network that is directly attached to you, simply deliver the packet on that network.

If the destination is not on a directly attached network, then do the following:
    1.  Search the routing table for an entry that matches the complete destination IP address.  If found, deliver to the specified router.
    2.  Search for an entry that matches the destination network number.  If found, deliver to the specified router.
    3.  Search for a default entry. If found, deliver to the specified router.
    .....If all three steps fail, the packet is undeliverable.

The table is populated one of three ways:
    1.  By having the network administrator enter the routing table into the kernel by using a series of commands;
    2.  By user-level routing protocols that we will discuss later;
    3.  By ICMP redirects.
 
Let's look at an example:
 
   A   B   C    D    E   F   G  H    I      J  K  L   M    N   O   P
   |      |     |     / \    |     |    |     |   / \      |   |    |    / \      |     |     |
 --------------   ------------------   --------------   ------------
  198.11.109.0      198.34.15.0      201.21.192.0     199.23.115.0
 
We'll assign the following IP addresses:
      A:                       198.11.109.1
      B:                       198.11.109.2
      C:                       198.11.109.3
      D (interface  1):   198.11.109.4

      D (interface  2):   198.34.15.1
      E:                       198.34.15.2
      F:                       198.34.15.3
      G:                       198.34.15.4
      H:                       198.34.15.5
      I (interface 1):     198.34.15.6

      I (interface 2):     201.21.192.1
      J:                        201.21.192.2
      K:                      201.21.192.3
      L:                       201.21.192.4
      M (interface 1):   201.21.192.5

      M (interface 2):   199.23.115.1
      N:                       199.23.115.2
      O:                       199.23.115.3
      P:                       199.23.115.4

The routing table for A is the following:
           198.11.109.0    198.11.109.1      N  interface_1
           0.0.0.0               198.11.109.4      N  interface_1

The first line of the table means if the destination address has 198.11.109.0 as the network number, deliver it directly out the network (note that A's address is in the second field, and that means deliver it directly).  The "N" means the first field is a network number (as opposed to a full IP address).

The second line is the default entry.  The "0.0.0.0" in a routing table means "the default route".  As you can see, the routing table says deliver all other destinations to machine D.

Very important:  Every router must be on a directly-attached network. You cannot specify a router on another network.  For example,
machine A could *not* have a table entry like the following:

          0.0.0.0       198.34.15.1  N  interface_1

because 198.34.15.1 is not on A's network!

The routing table for machine F would be the following:
           198.34.15.0    198.34.15.3  N  interface_1
           198.11.109.0  198.34.15.1  N  interface_1
           0.0.0.0            198.34.15.6  N  interface_1
 
Note that every router is on F's network.  Also, machine I is the best machine for a default router.  If we made machine D the default router, the routing table for F would be the following:
           198.34.15.0    198.34.15.3  N  interface_1
           201.21.192.0  198.34.15.6  N  interface_1
           199.23.115.0  198.34.15.6  N  interface_1
           0.0.0.0            198.34.15.1  N  interface_1

...and, that routing table has four entries instead of three, so it's not as good as the previous entry.

let's look at the routing table for machine M:
           201.21.192.0  201.21.192.5  N  interface_1
           199.23.115.0  199.23.115.1  N  interface_2
           0.0.0.0            201.21.192.1  N  interface_1
 

And finally the routing table for I:
          198.34.15.0   198.34.15.6      N  interface_1
          201.21.192.0  201.21.192.1   N  interface_2
          198.11.109.0  198.34.15.1     N  interface_1
          199.23.115.0  201.21.192.5   N  interface_2

Note that I does not have a default route in this case.  BUT, if machine P had a second interface that was connected to the internet, the routing table for I would be:
          198.34.15.0   198.34.15.6      N  interface_1
          201.21.192.0  201.21.192.1   N  interface_2
          198.11.109.0  198.34.15.1     N  interface_1
          0.0.0.0            201.21.192.5   N  interface_2