Static Routes That Track Interfaces or Other Routes

Problem

You want to install a static route only when an interface fails or a prefix drops out of the routing table.

Solution

One of the interesting new features in IOS Versions 12.3T and 12.4 is the ability to track things like interface status or routing table objects. This first example shows how to create a static route that tracks an interface:

Router#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#track 10 interface Serial0/0 line-protocol
Router(config-track)#delay down 5 up 30
Router(config-track)#exit
Router(config)#ip route 192.168.10.0 255.255.255.0 10.3.12.26 track 10
Router(config)#end 
Router#

This second example shows how to create a static route that tracks a prefix in the IP routing table:

Router#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#track 11 ip route 10.2.95.0 255.255.255.0 reachability
Router(config-track)#delay down 5 up 5
Router(config-track)#exit
Router(config)#ip route 0.0.0.0 0.0.0.0 10.3.12.26 track 11
Router(config)#end 
Router#

And the final example installs the static route when a combination of the previous conditions is met:

Router#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#track 12 list boolean and
Router(config-track)#object 10 not
Router(config-track)#object 11 
Router(config-track)#exit
Router(config)#ip route 192.168.13.0 255.255.255.0 10.3.12.26 

Get Cisco IOS Cookbook, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.