IP SLA is a powerful tool, which I will only scratch the surface of in this post in regards to route tracking. I had a scenario where the primary default route should be removed if the internet was no longer accessible through the primary interface. This can be achieved with weighted static routing, but the primary default route will only be removed if the primary interface is physically down. The more likely scenario exists where the primary interface is physically connected and up, but the ISP is having routing/peering issues and takes down your connection to the outside world. IP SLA can be used to simply ping an IP address, and if the ping is unsuccessful, the route is removed.
Here is a simple IP SLA configuration to ping 22.214.171.124 every 5 seconds:
ip sla 1
icmp-echo 126.96.36.199 source-ip 188.8.131.52
ip sla schedule 1 life forever start-time now
To track this IP SLA operation, we use the following command:
track 1 rtr 1 reachability
delay down 15 up 15
On newer versions of IOS, “rtr” will be replaced with “ip sla”. I added the “delay down 15 up 15” statement so that the track doesn’t report as “down” until ip sla has failed 3 times in a row. This is because I don’t want one ping to fail and have the route switched immediately. Conversely, on fail-back, I don’t just one ping to be successful before failing back to the primary route. This prevents route-flapping when interfaces/service is flapping.
I would consider it best practice to statically route to whatever IP address you are pinging for your IP SLA operation. Since I am pinging 184.108.40.206, and my gateway IP is 220.127.116.11 (theoretically), I add:
ip route 18.104.22.168 255.255.255.255 22.214.171.124
And finally, to add the track to my default route, I would use:
ip route 0.0.0.0 0.0.0.0 126.96.36.199 track 1
If you don’t trust pinging a single IP address, you can setup multiple IP SLA operations (IP SLA 2, IP SLA 3) and multiple tracks (Track 2, Track 3) and track all of them in a Track List. Example:
track 100 list threshold percentage
threshold percentage up 25
ip route 0.0.0.0 0.0.0.0 188.8.131.52 track 100
Each of the objects is a seperate IP SLA operation/track, and as long as =>25% of the objects are up, the list will be considered up. This is good idea to implement in case one of your ping destination happens to go down or stops responding to pings.