So I have a couple of routers connected to my network each linking to a different ISP. When an ISP goes down, I want to easily switch ISPs from the command line and these are the couple of lines I use to do so:
sudo ip route del default
if [ $1 == 'isp1' ]
echo "Switching ISP to $1"
sudo ip route add default via 192.168.1.1
echo "Switch ISP to ISP2"
sudo ip route add default via 192.168.0.1
I put this into a file (say
.isp), give it execute permissions, and then type
./.isp isp1 to switch to ISP 1. Typing anything else changes to ISP 2.
There is an
ip route change default option as well. But this is preferable as I would occasionally run into errors similar to
RTNETLINK answers: No such file or directory otherwise.
You can add the following code to display your current external IP and test your connection with a ping:
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
ping -n -c 4 18.104.22.168
(22.214.171.124 is one of Google's public DNS servers.)
Hope this helps someone.