|
lei gaowrote:
如果是电信断了,删除全部路由表,然后所有数据走网通线路.
当电信网络正常了,添加路由表,走策略,电信走电信,网通走网通 如果网通信号断了.删除添加的路由表.全部数据走电信 当网通信号正常了,添加删除的路由表,走策略,电信走电信,网通走网通. 谢谢.这是我测试过发现的问题.如果单独切换网关是不行的.线路还是走他添加默认的路由表.
Oct. 22
|
|
|
lei gaowrote:
LINUX双线自动切换脚本3.52008年12月19日 星期五 18:21
较之前的版本做了稍微的修改,优化了部分命令行,增加了LOG功能,方便管理员对线路状况的掌握. 特别鸣谢:天之蓝小样给予的支持. 您在使用时,请尊重别人的劳动成果,保留版本信息.谢谢. -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- #!/bin/sh #============================= #Script Name:Daker`s both WAN guard Shell for Linux #Author: Daker #Version: 3.5 #RUL:http://dakerbt.spaces.live.com #============================= #============================= #Both WAN IPaddress/gateway config tctip="" tctgw="" cncip="" cncgw="" lange="" #============================== #============================== #Both WAN Log config entry="100" #============================== if [ -n "`route -n | grep 0.0.0.0 | grep UG | grep $tctgw`" ]; then line="checl" else line="cnc" fi while true; do tctok="$(ping -c 1 $tctgw|grep "100% packet loss"|wc -l)" cncok="$(ping -c 1 $cncgw|grep "100% packet loss"|wc -l)" if [ $tctok -eq 0 ] && [ $cncok -eq 0 ] && [ $line != "checl" ]; then echo "start checl" date '+#Both network connected. %D %X' >>\log\checl.log if [ -n "`route -n | grep 0.0.0.0 | grep UG | grep $cncgw`" ]; then ip r re 0/0 via $tctgw fi if [ -n "`route -n | grep $tctip | grep UGH | grep $cncgw`" ]; then route del -host $tctip gw $cncgw fi if [ -n "`route -n | grep $cncip | grep UGH | grep $tctgw`" ]; then route del -host $cncip gw $tctgw fi line="checl" elif [ $tctok -eq 1 ] && [ $line != "cnc" ]; then echo "start cnc" date '+#disconnected from tct. %D %X' >>\log\checl.log if [ -n "`route -n | grep 0.0.0.0 | grep UG | grep $tctgw`" ]; then ip r re 0/0 via $cncgw fi if [ -n "`route -n | grep $cncip | grep UGH | grep $tctgw`" ]; then route del -host $cncip gw $tctgw fi if [ -z "`route -n | grep $tctip | grep UGH | grep $cncgw`" ]; then route add -host $tctip gw $cncgw fi line="cnc" elif [ $cncok -eq 1 ] && [ $line != "tct" ]; then echo "start tct" date '+#disconnected from cnc. %D %X' >>\log\checl.log if [ -n "`route -n | grep 0.0.0.0 | grep UG | grep $cncgw`" ]; then ip r re 0/0 via $tctgw fi if [ -n "`route -n | grep $tctip | grep UGH | grep $cncgw`" ]; then route del -host $tctip gw $cncgw fi if [ -z "`route -n | grep $cncip | grep UGH | grep $tctgw`" ]; then route add -host $cncip gw $tctgw fi line="tct" fi if [ -e \log\checl.log ];then logok="$(grep "#" \log\checl.log|wc -l)" if [ $logok -ge $entry ];then rm \log\checl.log -f fi fi sleep "$lange"s done 你这个脚本能切换网关,但是不能删除路由表,我都是过了.我这双线环境.我把电信信号断了,这个脚本能切换成网通的关.但是ping电信的DNS不通.必须把路由表删除了才可以.请完善下谢谢
Oct. 22
|