Gateway Switch script
Hi,
Does any body has a script to automatically switch the default gateway between two IPs. ?
I have two ISP connections. I want to switch between them when one is down
Regards
Murali
You could use something like this, run out of cron.
#!/bin/bash
$DEF='192.168.1.1'
$BACK='192.168.2.1'
$CURRENT=netstat -rn | grep "^0.0.0.0" | awk '{print $2}'
# if $DEF is current check and switch to backup if down if [ $CURRENT = $DEF ]; then ping -c1 -w5 $DEF
if [ $? > 0 ]; then
route del default gw $DEF
route add default gw $BACK
fi
# else check the backup and switch to def if down else ping -c1 -w $BACK
if [ $? > 0 ]; then
route del default gw $BACK
route add default gw $DEF
fi
fi
This is totally untested so you milage may vary.
Quoted 19 lines · Murali Potla
Hi,
Does any body has a script to automatically switch the default gateway between two IPs. ?
I have two ISP connections. I want to switch between them when one is down
Regards
Murali-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Jeff Largent ImageLinks, Inc.
Quoted 8 lines
Does any body has a script to automatically switch the default gateway between two IPs. ?
I have two ISP connections. I want to switch between them when one is down
You can set up your default route to be a multipath route. Then you could use both connections simultaneously and continue to use the other one if one is down. There is no need to switch default gateway with a script. Your kernel will figure out when to stop using the dead route and how to do NAT.
Check these urls:
http://lartc.org/howto/lartc.rpdb.multiple-links.html
http://www.ssi.bg/~ja/#routes
http://www.ssi.bg/~ja/nano.txt
Vitalie