k2p Padavan 离线自动重启,中继模式检测主路由不在自动重启方案

k2p 刷 Padavan 中继模式,在主路由维护或者更换后,k2p无法自动连接上,并给接入的设备分配ip。

所以添加一个脚本来实现 1分钟检测一次和主路由的连接情况,如果连接正常,那么什么也不做,如果连接异常,那么30秒后重启。

ssh 登陆路由 添加一个脚本

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
cat > /etc/storage/auto_reboot.sh << \EOF
#!/bin/bash
default_gateway='10.1.1.1' # 10.1.1.1 or 223.5.5.5
check_ip_available(){
    ping -c 3 $1 | grep packets | awk '{print $4}'
}
sleep 30
res=`check_ip_available $default_gateway`
if [ $(($res)) -eq 0 ];
then
    echo "rebooting..." 
    /sbin/reboot
fi
echo "nothing need todo" 
EOF
chmod +x  /etc/storage/auto_reboot.sh
/sbin/mtd_storage.sh save

自动定时运行脚本(每一分钟检测一次):
系统管理 - 服务 调度任务 (Crontab) 加入 */1 * * * * /etc/storage/auto_reboot.sh

同样也可以修改为 检测ping 一个国内稳定的公网ip .

# 旁路由方案自动切换网关

https://dev.leiyanhui.com/openwrt/auto-change-gatway/

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计