ISP Fail Over Script

advertisement

I used the [tag]ISP[/tag] [tag]failover[/tag] [tag]script[/tag] 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:


3 Responses to “ISP Fail Over Script”

  1. noor hidayat Says:

    Dial-up connections only >.>

  2. Planet Malaysia Says:

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

  3. zelik Says:

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

Leave a Reply