部分公网ip因不知原因无法访问国际互联网,但可以访问国内ip,例如百度可以访问,但亚马逊、必应、微软等国外网站无法访问, 需要重新拨号,获取新的ip才有可能访问成功
openwrt 中创建重启脚本 pingtest.sh ,设置到 cron 中定时检测即可
#!/bin/sh
# Script to check connectivity and restart network if condition met
# Ping www.baidu.com 3 times successfully but 8.8.8.8 fails 3 times
# Function to check if ping succeeds (returns 0 if at least one packet received)
ping_check() {
ping -c 3 -W 1 "$1" >/dev/null 2>&1
return $?
}
# Check www.baidu.com
if ping_check "www.baidu.com"; then
# If baidu succeeds, check 8.8.8.8
if ! ping_check "8.8.8.8"; then
# Condition met: restart network interface (assuming wan, adjust if needed)
/etc/init.d/network restart
logger "Network restarted due to baidu ping success but 8.8.8.8 failure"
fi
fi