Static routes are permanent entries that do not change. They can be configured in two ways: manually by using the route command, or through the use of two configuration files, /etc/defaultrouter and /etc/gateways . This section covers the use of the route command. The configuration files are discussed later in this chapter. The route CommandThe route command is used to manipulate the routing table manually. Routes can be added, deleted, and changed with this command. The general format of the route command is route add delete change < destination > < gateway > where < destination > is the host or network you are trying to reach and < gateway > is the router that will forward the packet to the destination.
Figure 6.1 shows a sample configuration with three networks, connected through the use of two routers, which are used here to illustrate static routes. Figure 6.1. A sample network configuration using routers.
Notice that the hosts on network A can communicate with hosts on network B or network C, only if they use router 1 as an intermediate gateway. The connection to network C is not so apparent because it relies on router 1 forwarding data to router 2 ”that is, it would take three hops for a host on network A to communicate with a host on network C, namely host on network A to router 1, router 1 to router 2, and router 2 to host on network C. Also, the hosts on network B can communicate with hosts on network A only if they use router 1 as an intermediate gateway. Similarly, the hosts on network B can communicate with hosts on network C only if they use router 2 as an intermediate gateway. If a host were to be added to network B, for example, then a static route would be added for both network A and network C, using router 1 and router 2 as gateways, respectively. The commands to add these routes would be ultra10# route add 192.168.28.0 192.168.29.1 add net 192.168.28.0: gateway 192.168.29.1 ultra10# route add 192.168.30.0 192.168.29.2 add net 192.168.30.0: gateway 192.168.29.2 When a host on network B sends a packet to a host on network A for example, it is passed to the router interface 192.168.29.1 for delivery. If the same host on network B sends a packet to a host on network C, it is passed to the router interface 192.168.29.2 for delivery. To delete the route to the network 192.168.30.0 , enter the following command: ultra10# route delete 192.168.30.0 192.168.29.2 delete net 192.168.30.0: gateway 192.168.29.2 If the route to network A changes from 192.168.29.1 to 192.168.29.55 , for example, enter the following command to modify the route: ultra10# route change 192.168.28.0 192.168.29.55 change net 192.168.28.0: gateway 192.168.29.55 For hosts on network A, all communications will pass through router 1, using the IP address 192.168.28.1 , so it would be easier to create a default route as follows: ultra10# route add default 192.168.28.1 add net default: gateway 192.168.28.1
The route monitor command can be used see any changes that are made to the routing table. When you run this command, it informs you straight away of the changes. The following example code shows the addition and subsequent deletion of a route. ultra10# route monitor got message of size 124 RTM_ADD: Add Route: len 124, pid: 368, seq 1, errno 0, flags:<UP,GATEWAY, \ DONE,STATIC> locks: inits: sockaddrs: <DST,GATEWAY,NETMASK> 192.168.28.0 192.168.29.1 255.255.255.0 got message of size 124 RTM_DELETE: Delete Route: len 124, pid: 369, seq 1, errno 0, flags:<UP, \ GATEWAY,DONE,STATIC> locks: inits: sockaddrs: <DST,GATEWAY,NETMASK> 192.168.28.0 192.168.29.1 255.255.255.0 The manipulation of routing table entries can become quite complex when you have to deal with numerous IP addresses. A simpler way of doing this is to use the /etc/inet/networks file to assign names to the networks and the /etc/inet/hosts file to assign names to the router interfaces. In the previous examples, you could add the following entries to /etc/inet/networks : networkA 192.168.28.0 networkB 192.168.29.0 networkC 192.168.30.0 and add the following entries to /etc/inet/hosts : 192.168.28.1 routerA 192.168.29.1 routerBtoA 192.168.29.2 routerBtoC 192.168.30.1 routerC Now, to add the route from a host on network B to any host on network A, use the following route command: ultra10# route add networkA routerBtoA add net networkA: gateway routerBtoA Configuration FilesTwo configuration files can be used to assign static routes: /etc/defaultrouter and /etc/gateways . Both of these files are described in this section:
The fields are described here:
A typical entry for the /etc/gateways file that adds a static route to the network networkA via the router routerA , which takes two hops, is shown here: net networkA gateway routerA metric 2 passive |