« History | Main | Sudden Death »

July 21, 2005

TechTip: Static Route? Gateway? Speak English...

Q: My server can't see Fred's server.

A: Do you have a route to it?

Q: What is a route?

A route is a set of directions that tell the computer how to send traffic to various destinations. You can see the current route table (even under windblows) by asking nicely:

bash-2.05# netstat -rn
Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ------ ---------
10.0.0.0 10.0.0.83 U 1 2907 hme0
224.0.0.0 10.0.0.83 U 1 0 hme0
default 10.0.0.8 UG 1 622
127.0.0.1 127.0.0.1 UH 2 3467 lo0

The -r displays the route table and the -n means to use numeric addresses (don't resolve them using DNS*).

We can ignore the 127.0.0.1 (loopback interface) and the 224.0.0.0 (multicast datagrams). That leaves us with a route to 10.0.0.0 (a network address) via 10.0.0.83 (our address) and a route to default (another network address) via 10.0.0.8 (some arbitrary ip address). Notice the flags (U, UG or UH), the 'U' means up, the 'G' means gateway and the 'H' means host. Note that the lack of a H implies that we are talking about a network route.

This table tells the sever that it can talk directly to the 10.0.0.0 network or at least some minor part of it. How much of the network we can talk to is governed by the netmask (which we are not going to discuss today). The table also says that all other requests should be sent to a gateway which has the address 10.0.0.8. Note that the gateway (or router) is on a network we can talk to (10.0.0.0). A gateway with some other address (say 142.68.81.93) would be useless because we would have no way to reach the gateway :-)

This table is normally build and maintained dynamically by the operating system but it is possible to add temporary changes:

route add net 10.0.2.0 10.0.0.52 1

The numbers are network (10.0.2.0), gateway / router (10.0.0.52) and hops (1). The hop-count is a way of telling the system how far away a particular gateway happens to be. This is used to make sure there are no loops in the route topology and can also be used to penalise a slower link**.

What if you wanted to make this route permanent? Enter the /etc/gateways file (which is very poorly documented on Solaris). Each line in the file should look like:

net <remote-network-ip> gateway <gateway-ip> metric <hop-count> passive
or
net <remote-network-ip> gateway <gateway-ip> metric <hop-count> active

If the gateway is really permanent, use the keyword 'passive'. Otherwise (keyword 'active') the operating system will occasionally check the route and delete it from the routing table if it appears to be down. Note that the gateway will be recreated on the next boot unless you remove the entry from the gateways file.

[* This is important if you are trying to work out why you can't see the DNS server. Leaving the -n will hang netstat as it does heaps and heaps of lookups...]

[** Say you have a high-speed route and a slow-speed route to a particular gateway. You would give the slow-speed router a higher hop-count (i.e. claim that it is further away) so that the high-speed route is used. If for some reason, the high-speed router fails, the system will "fall back" to using the low-speed route.]

Posted by Ozguru at July 21, 2005 06:00 AM