12 July 2012

FAILOVER WAN

#!/bin/bash
GW1=”192.168.100.254″
GW2=”192.168.200.254″
TESTIP=”192.71.220.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

No comments:

Post a Comment