快下班的时候,接到原同事Q 我,说它设置的VPN 的静态路由经常过一段时间很奇怪的就没了,
他开了权限给我,我上去看了看,VPN 采用的是 l2tp 的源码包,ifconfig 如下:
eth0 Link encap:Ethernet HWaddr 00:0C:29:25:47:EA
inet addr:192.168.0.152 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe25:47ea/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:21524727 errors:0 dropped:0 overruns:0 frame:0
TX packets:29594226 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3783489548 (3.5 GiB) TX bytes:5354364577 (4.9 GiB)
ppp0 Link encap:Point-to-Point Protocol
inet addr:10.208.65.11 P-t-P:10.208.65.10 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:3 errors:0 dropped:0 overruns:0 frame:0
TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:30 (30.0 b) TX bytes:48 (48.0 b)
route -N 结果如下:
Destination Gateway Genmask Flags Metric Ref Use Iface
10.208.65.10 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0
172.30.10.6 10.208.65.10 255.255.255.255 UGH 0 0 0 ppp0
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
后面跟他确认,是第二条静态路由手工增加的。问题搞清楚之后,就知道原因是什么--网络中断。
ppp 断开后,那个网卡上的路由就没了,我手工停掉VPN 的进程,route -N 路由表如下:
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
几分钟之内,VPN 自动重连后,路由表如下:
Destination Gateway Genmask Flags Metric Ref Use Iface
10.208.65.10 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
最早的想法是在 /etc/sysconfig/network-scripts/ 下面增加一个 route-ppp 文件,把路由丢进去,让它重新
拨号的时候,会自动执行,试过两次,发现没有效果,看来这个拨号的是不走网卡接口的路由了。
也就是,这条静态路由,是木有办法自己加上去的,得人工干预了。由于网络的原因,不确定VPN 啥时候回
中断,我回复他我给出三个方法:
1, 使用crontab 计划任务,每分钟执行一个脚本,判断路由是否不存在,如果不存在,则执行路由命令添加
指定路由;
2, 使用daemontools 开一个程序,同样监控脚本判断路由是否正常,如果不正常,则执行路由命令添加指
定路由;
3, 想法子找到拨号的拨号的脚本,在拨号成功后,添加静态路由;
前两种方法,感觉不是很可取,后面我还是帮他找到了一个 /etc/ppp/ip-up 文件。添加该路由:
/sbin/route add -host 172.30.10.6/32 gw 10.208.65.10
测试后,即使 VPN 端口重拨,会自动的执行这条路由命令。
没有评论:
发表评论