The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Special Forums > IP Networking
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #5 (permalink)  
Old 02-24-2008
bakunin bakunin is online now
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,103
The "default route" may be shown as an attribute for eth0 but *every* IP host has one and exactly one default route.

A route is telling the IP stack (and, regardless of the number of interfaces, there is only one IP stack per host) that "everything directed to network <destination> is to be sent to <gateway>, <gateway> will know how to handle it". "<network>" in this regard is a bit of a stretch, it can be a "network" consisting of only one host, if the subnet mask is all bits set to 1.

A "default" route is nothing different from that, just that "destination" is not a network or a host, but "everything not covered by other rules".

For instance:

your IP networks: 192.168.1/24, 192.168.2/24 in each of them your own IP adress will be 100. There is a router on network 192.168.1, which connects the network(s) to the world and has the adress 1 in the network.

Your IP address layout:

eth0: 192.168.1.100 / 255.255.255.0
eth1: 192.168.2.100 / 255.255.255.0

Your routing table (i do that on an AIX box, so it looks a bit different from Linux):
Code:
# netstat -rn
Routing tables
Destination        Gateway           Flags   Refs     Use  If   Exp  Groups

Route Tree for Protocol Family 2 (Internet):
default            192.168.1.1       UG        9    229328 en0      -      -   =>
192.168.1/24       192.168.1.100     U         0         0 en0      -      -   =>
192.168.2/24       192.168.2.100     U         0         0 en1      -      -   =>
The IP stack will now work like that: if it has to send a packet to a destination on one of "its own" networks (192.168.1/2.x) it will do so using eth0 or eth1, depending on rule 2 or 3.

If it has to send a package to 192.168.3.100 (or any other network), it will first consult all the rules it knows (2&3), finding out that no one fits. Now it falls back on its default route, which tells it to send it faithfully to 192.168.1.1, a host who (hopefully) will know what to do with it. Now it again looks up how to find 192.168.1.1 and - bingo! - it knows from rule 2 how to reach that host.

If the router would be moved from 192.168.1.1 to 192.168.2.1 you would have to change the default route and in the same way the packet would leave the host via eth1 instead of eth0.

I hope this clears things up.

bakunin
Reply With Quote