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 18.104.22.168 every 5 seconds:
ip sla 1 icmp-echo 22.214.171.124 source-ip 126.96.36.199 frequency 5 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 withdrawn 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 188.8.131.52, and my gateway IP is 184.108.40.206 (theoretically), I add:
ip route 220.127.116.11 255.255.255.255 18.104.22.168
And finally, to add the track to my default route, I would use:
ip route 0.0.0.0 0.0.0.0 22.214.171.124 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 object 1 object 2 object 3 object 4 threshold percentage up 25 ip route 0.0.0.0 0.0.0.0 126.96.36.199 track 100
Each of the objects is a seperate IP SLA operation/track, and as long as = or >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.