The route Command

Additional static routes are defined by the route command. It allows anyone to display the routing table and allows the root user to add and delete routes in the table. The system administrator added this static route to the sample routing table we saw in Listing 7.3:

172.16.50.0 172.16.55.36 255.255.255.0 UG 0 0 8 eth0

The route statement that creates this route is route add -net 172.16.50.0 netmask 255.255.255.0 gw 172.16.55.36

Examining this command shows almost everything you need to know about the route command syntax. All route commands start with an option that defines the "action" of the route command, which is either add or delete. All of the sample commands add routes to the routing table. To change a route, first delete it and then add it back in with the necessary corrections.

The -net option tells route that you are adding a network route. The alternative is -host for a host-specific route, but this is rarely used because most routes are network routes.

The -net option is followed by the destination address and by the network mask that is used to determine the network portion and the host portion of the address. The network mask must be preceded by the keyword netmask.

Warning Always define the netmask value yourself. If you don't, the address is interpreted using the natural mask, which means that the address is interpreted according to the old address class rules. Be specific. Define the mask yourself.

All of the sample route commands end with either an external gateway or a local device name. When an external gateway is used, it is defined by the gw option and the IP address of the gateway. When the interface device name is used, it is usually preceded by the keyword dev, although this is not required. The network interface name is included on a route statement that defines the connection of the device to the local network. On other route statements, the interface name is optional. Use the device name on all route statements when you have more than one interface to ensure that the route uses the interface that you intend.

Was this article helpful?

0 0

Post a comment