赞
踩
上一篇写到在dnsmasq里面增加自动两个网关地址,自动进行主备切换并未生效, 所以做了一版本的优化
我这边的设备是一台刷了梅林固件的华硕路由(192.168.50.1)和一个跑在群晖VMM上面的openwrt旁路由(192.168.50.99)
华硕路由(192.168.50.1)定时探活openwrt(192.168.50.99)是否在线.并作出后面的网关/DNS切换
- #!/bin/sh
- bypass=192.168.50.99
- default_ip=192.168.50.1
-
- network()
- {
- #这里比较取巧的是通过判断路由器的页面能否打开判断旁路由在不在线
- local timeout=2
- #call bypass server
- local ret_code=`curl -I -s -m ${timeout} ${bypass} -w %{http_code} | tail -n1`
- if [ "x$ret_code" = "x000" ]; then
- return 1
- else
- return 0
- fi
- }
-
- changeGateway()
- {
- #confirm whether default now
- local resp=`grep $1 /jffs/configs/dnsmasq.d/openwrt.conf|wc -l`
- if [ $resp -gt 0 ];then
- /usr/bin/logger "[bypass detect] gateway don't need to change"
- return 0
- else
- #need change gateway
- /usr/bin/logger "[bypass detect] change gateway from $2 to $1"
- sed -i "s/$2/$1/g" /jffs/configs/dnsmasq.d/openwrt.conf
- service restart_dnsmasq
- /usr/bin/logger "[bypass detect] change gateway to $1 success"
- return 0
- fi
- }
-
- network
- if [ $? -eq 0 ];then
- changeGateway $bypass $default_ip
- else
- changeGateway $default_ip $bypass
- fi
能够达到在旁路由下线后,在探活间隔(1分钟)和DHCP租约时长(5分钟)内,客户端切换网关和DNS
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。