Using Static Routing

Problem

You want to configure a static route.

Solution

You can configure a static route with the ip route command, as follows:

Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#ip route 10.35.15.5 255.255.255.255 Ethernet0
Router(config)#end 
Router#

You can also configure a static route to point to a particular next hop router:

Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface Serial0
Router(config-if)#ip address 10.35.6.2 255.255.255.0 
Router(config-if)#exit
Router(config)#ip route 172.16.0.0 255.255.0.0 10.35.6.1 2
Router(config)#end
Router#

If you want to ensure a route remains in place even if the next-hop IP address becomes unreachable, or the interface goes down, you can use the permanent keyword:

Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#ip route 10.35.15.5 255.255.255.255 Ethernet0 permanent
Router(config)#ip route 172.16.0.0 255.255.0.0 10.35.6.1 2 permanent
Router(config)#end
Router#

You can also manually configure routing tags that use static routes by using the tag keyword:

Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#ip route 172.16.0.0 255.255.0.0 10.35.6.1 2 tag 36291
Router(config)#end
Router#

 

Discussion

The first version sends all packets destined to the single host 10.35.15.5 out through the Ethernet0 interface. In this case, the router will need to figure out which device on this segment to forward the packet to, because it must put the MAC address of the next hop router in the Layer 2 frame header. The standard mechanism for associating IP addresses with MAC addresses is the Address Resolution Protocol (ARP). The router will send out an ARP request onto the Ethernet segment. If the device that owns the packet's destination IP address happens to be on this segment, it will respond with its MAC address. Otherwise, a router that is configured for Proxy ARP will have to respond on its behalf. This is important because if you do not have Proxy ARP configured on the next hop router, this command will fail. So for multiple access media such as Ethernet segments, we recommend using specifying the IP address of the next hop router rather than the interface.

Please refer to Chapter 22 for more information about enabling and disabling Proxy ARP.

You can also specify a point-to-point media such as a Serial interface for the route destination:

Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#ip route 10.35.15.5 255.255.255.255 Serial0 5
Router(config)#end
Router#

In this case there is no ambiguity. You can reach only one other device through this Serial interface, so the Proxy ARP issues that we just described do not apply.

The ip route command in the second example affects any packet whose destination address is in the range from 172.16.0.1 to 172.16.255.254, which will be forwarded to the next hop router, 10.35.6.1:

 Router(config)#ip route 172.16.0.0 255.255.0.0 10.35.6.1 2

The last number in this ip route command, 2, is the administrative distance for this route. This specifies a distance value that indicates how good this route is. The router will use this distance value to help it to decide between routes to the same destination prefix from different sources. For example, if you have more than one static route to the same destination, or if the router has learned another route to this destination via RIP, it will compare this administrative distances and use the route with the lowest distance value.

If there is no administrative distance value, as in the first example, the router will use a default value of 1.

The syntax for static routes specifies both an IP address and a netmask. This follows the standard rules for netmasks. However, it is useful to remember that the static route statement only controls how packets should be handled on this router. For example, suppose the range 172.16.0.0/16 includes the networks 172.16.1.0/24, 172.16.2.0/24, 172.16.5.4/30, and 172.16.5.8/30. If all the paths to all of these networks go through the router whose address is 10.35.6.1, then they can all be taken together with the same single route statement, as follows:

Router(config)#ip route 172.16.0.0 255.255.0.0 10.35.6.1 2

It is interesting to see what happens when you need to break up a range of addresses. Carrying on with the same example, suppose there is another network, 172.16.3.0/24, that is connected through a different next-hop router, 10.35.7.2. In this case, you can configure the router as follows:

Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#ip route 172.16.0.0 255.255.0.0 10.35.6.1 2
Router(config)#ip route 172.16.3.0 255.255.255.0 10.35.7.2 2
Router(config)#end
Router#

This may appear to have a conflict, because 172.16.3.0/24 is contained within the range 172.16.0.0/16, but there is in fact no conflict because of the longest match rule that we discussed earlier in this chapter. Also note that the router will use the more specific route, even if it has a higher administrative distance. The distance values are used only when selecting between routes with the same mask length. So for example, you could configure two static routes to the same destination:

Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#ip route 172.16.3.0 255.255.255.0 10.35.6.1 2
Router(config)#ip route 172.16.3.0 255.255.255.0 10.35.7.3 5
Router(config)#end
Router#

In this case, as long as the router has a route for the better next hop, 10.35.6.1, it will use only this line. The router will install the other route with the higher distance only if it can't reach the better next-hop device.

Note that this is a cumbersome and unreliable way of achieving automatic rerouting because it works only when the route to the next hop disappears, not when the next hop itself becomes unavailable. So, for example, if these two next hop routers were connected through different physical interfaces, and one of those interfaces went down, the router could switch to the router with the higher distance. But if both devices were on the same directly connected Ethernet segment, this would not provide a fail-over. So while this method is useful for some limited applications, in general it is better to use a dynamic routing protocol such as RIP, EIGRP, or OSPF, which are described in later chapters.

By default, the router does this adjustment to evaluate the validity of the next-hop device once every 60 seconds. In 12.3(10), Cisco introduced a new command that allows you to change this time if you need a faster update period:

Router(config)#ip route static adjust-time 30

In this example, we have reduced the adjust-time interval for next-hop evaluation of static routes from 60 to 30 seconds. This has the obvious effect of improving convergence times for networks with static routes, but it also has some negative consequences. If you have a lot of static routes, setting the adjust-time interval too low can cause CPU overhead problems.

The third example in this recipe uses the permanent keyword:

Router(config)#ip route 10.35.15.5 255.255.255.255 Ethernet0 permanent
Router(config)#ip route 172.16.0.0 255.255.0.0 10.35.6.1 2 permanent

You would use this when you want to ensure that the static route always remains in the routing table, even if the next-hop interface is down. There is sometimes a danger that the dynamic routing protocol will install a route that you do not want to use, and it may be preferable to drop the packets than to use the dynamic route. For example, if you had a private link to another IP network, and this link went down, you might not want your routers to try to find a path via the public Internet, even if one were advertised. This is sort of the opposite of the floating static route of Recipe 5.5.

The last example in this recipe uses routing tags:

Router(config)#ip route 172.16.0.0 255.255.0.0 10.35.6.1 2 tag 36291

Route tags are used when redistributing from one routing protocol to another. They provide a convenient way to tell which routes came from what external protocols or networks. This concept will be discussed in more detail in the Chapters 6, 7, 8, and 9.

See Also

Recipe 5.5; Chapters 6, 7, 8, 9, and 22





Cisco IOS Cookbook
Cisco IOS Cookbook (Cookbooks (OReilly))
ISBN: 0596527225
EAN: 2147483647
Year: 2004
Pages: 505
Simiral book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net