ISP Fail Over Script
Posted by Planet Malaysia on September 8, 2006
I used the ISP failover script for my personal reference which I get an idea(modify) from Shorewall malling list
#!/bin/sh
#Purpose: If main ISP(Maxis) down then it
will automatic switch to second ISP(TMNET)
#Note: Please make sure this script run in the
cronjob every 5 minutes
#Tips: Use command "route -n" for checking
default gateway
ISP1=xx.xx.xx.xx
ISP2=xxx.xxx.xxx.xxx
switch_time()
{
/sbin/route del default
/sbin/route add default gw $ISP2
}
switch_maxis()
{
/sbin/route del default
/sbin/route add default gw $ISP1
}
if /bin/ping -c1 -q www.google.com >/dev/null 2>&1;
then
echo "MAXIS GATEWAY is alive"
/sbin/ip route show
exit 0
else
if /sbin/route -n | /bin/grep '^0.0.0.0' | /bin/grep
"$ISP1"; then
/sbin/ip route flush cache
switch_tm
/sbin/route -n
/bin/echo "ISP Switch to TMNET GATEWAY" |/bin/mail -s
"ISP switch to TMNET GATEWAY" alert@yourdomain.com
else
if /sbin/route -n | /bin/grep '^0.0.0.0' | /bin/grep "$ISP2"; then
/sbin/ip route flush cache
/sbin/route -n
/bin/echo "ISP Switch to MAXIS GATEWAY" |/bin/mail -s
"ISP switch to MAXIS GATEWAY" alert@yourdomain.com
switch_maxis
fi
fi
Possibly Related Posts:
- How to Install Webmin on OpenFiler
- lppasswd: Unable to open passwd file: Permission denied
- How To Capture PUTTY Session Log
- How to Add Date And Time To Your Bash History on SuSE Linux
- How to clean EMC CX 3-80 Dirty Cache?
Comments
4 Responses to “ISP Fail Over Script”
Leave a Reply
Dial-up connections only >.>
Hi Noor Hidayat, I used this script on “fixed IP address” in my Linux box.
just to let you know, missing a final fi at end of ur posted script =)
yes missing fi at the end of this script,
$ sudo vim /etc/networkfailover-script
$ sudo chmod +x /etc/networkfailover-script
$ /etc/networkfailover-script
How to make cronjob every 5 minutes
http://www.foogazi.com/2008/04/01/quickzi-how-to-set-cron-to-run-every-5-minutes/