ISP Fail Over Script

Posted by Planet Malaysia on September 8, 2006

advertisement

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:


Comments

4 Responses to “ISP Fail Over Script”

  1. noor hidayat on September 8th, 2006 4:47 pm

    Dial-up connections only >.>

  2. Planet Malaysia on September 8th, 2006 7:17 pm

    Hi Noor Hidayat, I used this script on “fixed IP address” in my Linux box.

  3. zelik on July 16th, 2008 1:30 pm

    just to let you know, missing a final fi at end of ur posted script =)

  4. Mahmoud Ibrahim on July 22nd, 2010 3:49 pm

    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/

Leave a Reply




Planet Malaysia

  • Follow us on Twitter


  • web www.planetmy.com