To check the connectivity we can use the IP SLA feature in Cisco IOS which will be constantly pinging the internet address as soon as the icmp check will fail it will change the priority of the route so the traffic will get out through the other link.
First we create our IP SLA cinfig. In this example we want to ping the default gateway so we can check if the internet connectivity is working
ip sla monitor 50
type echo protocol ipIcmpEcho 22.214.171.124
ip sla monitor schedule 1 life forever start-time now
Next we create a tracked object. This one points to the reachability of the IP SLA. Note that the number 50 relates to the ip sla monitor number.
track 50 rtr 1 reachability
Next we create an ACL. This permits ICMP to our default gateway. This is used in our route map to determine the reachability.
ip access-list 101 permit icmp any host 126.96.36.199
Next we create our route map. We match on the ACL we just created, then set the next hop as the preferred provider IP 188.8.131.52. You must set the interface to null0.
route-map DEFAULT-ROUTE-POLICY permit 10
match ip address 101
set ip next-hop 184.108.40.206
set interface null 0
Next we create a local routing policy to use our newly created route map.
ip local policy route-map DEFAULT-ROUTE-POLICY
Finally we put in our default routes. The first default route points to our preferred provide and we append the tracking to it. We then add the second default route with a higher weight (floating static route). What this does for us is the router will track the preffered default route. If for some reason we lose connectivity (from the IPS SLA) the route will be removed and any secondary default route will be added. In this example the new default route will point to 220.127.116.11
ip route 0.0.0.0 0.0.0.0 18.104.22.168 track 10
ip route 0.0.0.0 0.0.0.0 22.214.171.124