使用硬件路由刷OpenWRT系统时,PPPoE拨号一切正常,后面为精简硬件环境,撤掉了硬件路由器,改为软路由,也就是在虚拟机中运行OpenWRT,配置配置迁移后都还正常,拨号也能上网,但总是莫名奇妙的断网,登录后台查看接口状态,发现PPPoE接口刚刚发生了重连,也重新获取到了ip,但就是网络不通...只有手动重启该接口后,重新拨号,网络才能恢复。
在网上查了一些资料发现有说在接口高级设置中启用LCP响应故障阈值能解决这个问题,实验后发现依旧无法保证重连后网络正常。无奈只能自己排查了。
OpenWRT系统提供了一个接口的事件脚本,也就是在/etc/hotplug.d/iface/下添加脚本,系统会在接口状态发生改变时运行这些脚本。于是我就写了一个wan-pppoe的脚本,用来纪录发生断线重连的时候的一些细节信息,其内容如下:
WAN_LAST_STATE="$(cat /var/log/wan-last.log)" [ "$INTERFACE" = wan ] || exit 0 if [ "$ACTION" != "$WAN_LAST_STATE" ];then echo "$ACTION" > /var/log/wan-last.log echo "$(date)" "$ACTION" >> /var/log/wan-state.log if [ "$ACTION" = ifupdate ];then curl http://www.baidu.com > /dev/null echo "$(date)" "netstat - $?" >> /var/log/wan-state.log echo "$(route -n)" >> /var/log/wan-state.log echo "$(ip address show dev pppoe-wan)" >> /var/log/wan-state.log fi else exit 0 fi
主要任务就是在wan口发生update的时候去curl一下百度看网络是否正常,然后再记录一下内核路由信息等等。后面就是等他某天出现这个情况的时候,分析日志了。
Update
今天再次遇到了这个情况,直接cat /var/log/wan-state.log
[root@openwrt:~]$ cat /var/log/wan-state.log Wed Aug 17 02:07:53 UTC 2022 ifup Wed Aug 17 18:04:08 UTC 2022 ifdown Wed Aug 17 18:04:14 UTC 2022 ifup-failed Wed Aug 17 18:11:58 UTC 2022 ifup Wed Aug 17 18:11:58 UTC 2022 ifupdate Wed Aug 17 18:11:58 UTC 2022 netstat - 0 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 6.6.6.1 0.0.0.0 UG 0 0 0 pppoe-wan 6.6.6.1 0.0.0.0 255.255.255.255 UH 0 0 0 pppoe-wan 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 26: pppoe-wan: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1492 qdisc fq_codel state UNKNOWN group default qlen 3 link/ppp inet 6.6.6.2 peer 6.6.6.1/32 scope global pppoe-wan valid_lft forever preferred_lft forever inet6 fe80::20c:2902:a32d:10c1/10 scope link valid_lft forever preferred_lft forever Sat Aug 20 03:53:34 UTC 2022 ifdown Sat Aug 20 03:53:34 UTC 2022 ifup-failed Sat Aug 20 03:53:35 UTC 2022 ifup Sat Aug 20 03:53:35 UTC 2022 ifupdate Sat Aug 20 03:53:40 UTC 2022 netstat - 6 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 6.6.6.1 0.0.0.0 255.255.255.255 UH 0 0 0 pppoe-wan 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 31: pppoe-wan: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1492 qdisc fq_codel state UNKNOWN group default qlen 3 link/ppp inet 6.6.6.2 peer 6.6.6.1/32 scope global pppoe-wan valid_lft forever preferred_lft forever inet6 fe80::20c:29f7:d32d:10c1/10 scope link valid_lft forever preferred_lft forever
可以看到,在发生重连之后,莫名奇妙的丢了默认网关的路由信息,手动添加一下路由试试
[root@openwrt:~]$ route add default gw 6.6.6.1
测试后正常,总结出来的结果就是虚拟机跑OpenWRT进行PPPoE拨号时,在断线重连后,会有一定概率丢失默认路由信息,造成断网现象。
解决方法嘛,我还在hotplug事件中进行,当出现curl baidu.com失败时,查一下pppoe的对端ip,再次添加默认路由就行了。修改后的脚本内容如下:
WAN_LAST_STATE="$(cat /var/log/wan-last.log)" [ "$INTERFACE" = wan ] || exit 0 if [ "$ACTION" != "$WAN_LAST_STATE" ];then echo "$ACTION" > /var/log/wan-last.log echo "$(date)" "$ACTION" >> /var/log/wan-state.log if [ "$ACTION" = ifupdate ];then curl http://www.baidu.com > /dev/null if [ $? != 0 ];then GW=$(route | grep pppoe | awk '{print $1}') route add default gw $GW fi echo "$(date)" "netstat - $?" >> /var/log/wan-state.log echo "$(route -n)" >> /var/log/wan-state.log echo "$(ip address show dev pppoe-wan)" >> /var/log/wan-state.log fi else exit 0 fi
-
« 上一篇:
记一次NFS故障
-
Calibre-web添加外部链接(友谊链接)
:下一篇 »