this bellow is simple auto change default gateway for internet
i have two isp internet :
server with gateway : 192.168.1.17
server with backup gateway : 192.168.1.59
use proxy for default internet in officce that run script auto cahange gateway
first use the default gateway is 192.168.1.17
i use the google's dns ( 8.8.8.8 ) for test internet connection via gateway 192.168.1.17 every 3 minute with crontab do with swroute.sh
second use route host google's dns via 192.168.1.17
#route add -host 8.8.8.8 gw 192.168.1.17
i use ping for test internet connection for first isp ( 192.168.1.17 )
and i create swroute.sh with bash script for test connection and switch default default routing
#nano swroute.sh
-------------------------------------------------------------------------------------------------------------------------
#!/bin/bash
loss="`ping 8.8.8.8 -w 20 | grep loss | awk '{print $6}' | sed '$s/.$//'`"
route="`route -n | head -3 | grep eth0 | awk '{print $2}'`"
isp1="192.168.1.17" isp2="192.168.1.59"
if [ $route == $isp1 ];
then
if [ $loss -gt 15 ]
then
route del default gw 192.168.1.17
route add default gw 192.168.1.59
echo "line via isp2--- pada: `date`" >> /root/ping/logswitch.txt
else
echo "still via isp1 "
fi
elif [ $loss -gt 15 ];
then echo " still via isp2"
else
route add default gw 192.168.1.17
route del default gw 192.168.1.59
echo "> back to isp1 : `date`" >> /root/ping/logswitch.txt
fi
------------------------------------------------------------------------------------------------------------------------
#chmod +x swroute.sh
add crontab every 3 minute
*/3 * * * * /path/path/swroute.sh
this script work for my slackware server
Happy Slackware .....
Tidak ada komentar:
Posting Komentar