Results 1 to 2 of 2
I had two internet connection
1. Mtnl (192.168.0.1 Gateway)
2. Tata (192.168.1.2 Gateway
Mtnl isp connection is on DSL 502t small adsl modem & Tata isp connection is on Zyxel ...
- 07-22-2011 #1Just Joined!
- Join Date
- May 2007
- Posts
- 3
dns failover script
I had two internet connection
1. Mtnl (192.168.0.1 Gateway)
2. Tata (192.168.1.2 Gateway
Mtnl isp connection is on DSL 502t small adsl modem & Tata isp connection is on Zyxel P-600 series modem
I had configured both isps connection on ubantu 11.04 desktop edition, my internet works fine but i can use only one connection at a time so we want to use mtnl isp connection as a backup connection
I had downloaded 2 or 3 scripts from internet and tested on both connection it successfully give backup of second connection but only when you switch off the modem it cannot switch the second gateway when i had pulled out the adsl connection cable for testing.
It means the failover scripts only works when I switch off the modem, I need a failover script which works when the adsl means the internet line goes off not to when i switch of the modem
Here is the script which i had tested but not works as a backup
Script
#!/bin/bash
GW1="192.168.0.1"
GW2="192.168.1.2"
TSTIP="59.185.3.10" # Any reliable Internet ip that responds to ping.
CURGW=`/sbin/route -n |awk '/^0.0.0.0/ {print $2 }'`
if ping -w2 -c3 $TESTIP >/dev/null 2>&1; then
echo "Active ISP is Ok."
else
if [ "$CURGW" = "$GW1" ]; then
NEWGW="$GW2"
else
NEWGW="$GW1"
fi
/sbin/route del default
/sbin/route add default gw $NEWGW
fi
Please provide me the best script which will work as a isp failover
- 07-23-2011 #2
I'm guessing the script fails to switch to $GW2 when your route table has no default gateway ($CURGW="" ?). What do you think?
I'll say to try changing $GW2 with $GW1 on the if. I mean, change to:
if [ "$CURGW" = "$GW2" ]; then
NEWGW="$GW1"
else
NEWGW="$GW2"
and see if that solve the failing situation you describe.
If so, you'll have to add a if condition. Something like this may do it.
...
CURGW=`/sbin/route -n |awk '/^0.0.0.0/ {print $2 }'`
if [ ! -n "$CURGW" ]; then
CURGW="$GW2"
/sbin/route add default gw $CURGW
fi
if ping -w2 -c3 $TESTIP >/dev/null 2>&1; then
echo "Active ISP is Ok."
else
if [ "$CURGW" = "$GW1" ]; then
NEWGW="$GW2"
else
NEWGW="$GW1"
fi
/sbin/route del default
/sbin/route add default gw $NEWGW
fi
As it seems, you are pinging your own server, so I see nothing against this solution (if it works, that is), but I'm no expert.
Regards
Luis


Reply With Quote