UNIX System Administration Handbook - Evi Nemeth [184]
Second, there may be no route that matches the destination address. In this case, the default route is invoked if one exists. Otherwise, an ICMP “network unreachable” message is returned to the sender. Many local area networks have only one way out, and their default route points to it. On the Internet backbone, the routers do not have default routes—the buck stops there. If they do not have a routing entry for a destination, that destination cannot be reached.
Each route command adds or removes one route. The format is usually
route [-f] op [type] destination gateway [hop-count]
The op argument should be add to add a route and delete to remove one. Some versions of route have other values that op can assume, such as get, change, flush, and monitor. destination can be a host address, a network address, or the keyword default. Some systems represent the default route by the network address 0.0.0.0.
The gateway is the machine to which packets should be forwarded. It must be on a directly connected network; forwarding can only be performed one hop at a time. Some versions let you specify an interface instead of (or along with) the gateway.
hop-count is the number of forwardings required to reach the destination. Some operating systems require the hop count, others allow it but ignore it, and others have made it obsolete and wrong to include. On operating systems that require a hop count, the value need not be exact, and it is often set to 1.
FreeBSD has not only eliminated the hop-count variable but, if you inadvertently use it, it will be interpreted as the netmask. A netmask of 1 is not very useful!
The optional type argument supports host routes, which apply to a complete IP address (a specific host) rather than to a network address. The values net and host are accepted for the type parameter. If a type isn’t specified, route checks the host part of the destination address to see if it’s zero. If the host part is 0 or the address is a network defined in the /etc/networks file (if your system has one), then the route is assumed to be a normal network route.19
Since route cannot magically know which network numbers have been subnetted, you must frequently use the type field to install certain routes. For example, the address 128.138.243.0 refers to a subnetted class B network at our site, but to route it looks like a class B address of 128.138 with a host part of 243.0; you must specify the net option to deconfuse route. In general, it’s good hygiene to provide an explicit type for all routes that involve subnets.
route delete destination removes a specific entry from the routing table. route -f removes (flushes) all routing entries from the table. If combined with an add command, route -f first flushes the table and then makes the requested change.
Systems derived from late Berkeley releases use route flush instead of route -f. They also use -net and -host rather than net and host.
Red Hat uses BSD’s -net and -host convention but not route flush; in fact, Red Hat seems to provide no way at all to flush the routing table in one step.
To inspect existing routes, use the command netstat -nr. See page 631 for more information about netstat.
Default routes
A default route causes all packets whose destination network is not found in the kernel’s routing table to be sent to the indicated gateway. To set a default route, simply add the following line to your startup files:
route add default gateway-IP-address
Rather than hardcoding an explicit IP address into the startup files, most vendors have their systems get the gateway IP address from a configuration file. The way that local routing information is integrated into the startup sequence is unfortunately different for each operating system. Table 13.13 summarizes the incantations necessary on our four example systems.
Table 13.13 How to set the default route
Where the Variable column lacks an entry, just put the IP