====== 如何在Android手机上删除路由表 ====== 我在G1上用OpenVPN连上过VPN之后,那个路由信息一直保存在系统中,就算OpenVPN断开了,那些路由信息仍然存在。 这导致我再开GPRS上网的时候上不了网,除非重启手机。 ====== 查看当前路由 ====== 用adb shell连上G1查了一下当前路由: # busybox route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.8.0.1 10.8.0.17 255.255.255.255 UGH 0 0 0 tun0 10.8.0.17 0.0.0.0 255.255.255.255 UH 0 0 0 tun0 0.0.0.0 10.8.0.17 128.0.0.0 UG 0 0 0 tun0 128.0.0.0 10.8.0.17 128.0.0.0 UG 0 0 0 tun0 此时连移动的网络都没连上,但那些路由信息仍然保留在。 # busybox ifconfig lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:1564 errors:0 dropped:0 overruns:0 frame:0 TX packets:1564 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:120896 (118.0 KiB) TX bytes:120896 (118.0 KiB) tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:10.8.0.18 P-t-P:10.8.0.17 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:117 errors:0 dropped:0 overruns:0 frame:0 TX packets:15349 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:11534 (11.2 KiB) TX bytes:1152208 (1.0 MiB) ====== 删除路由 ====== 于是一条一条删除: busybox route del -net 10.8.0.1 netmask 255.255.255.255 busybox route del -net 10.8.0.17 netmask 255.255.255.255 busybox route del -net 0.0.0.0 netmask 128.0.0.0 busybox route del -net 128.0.0.0 netmask 128.0.0.0 再查看一下当前路由,已经清空了 # busybox route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface ====== 重启GPRS连接 ====== 再打开GPRS,连上移动的cmnet: # busybox ifconfig lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:1564 errors:0 dropped:0 overruns:0 frame:0 TX packets:1564 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:120896 (118.0 KiB) TX bytes:120896 (118.0 KiB) rmnet0 Link encap:Ethernet HWaddr 92:E8:B6:FA:8A:48 inet addr:10.110.183.24 Bcast:10.110.183.27 Mask:255.255.255.252 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:6883 errors:0 dropped:0 overruns:0 frame:0 TX packets:6556 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:6254640 (5.9 MiB) TX bytes:667584 (651.9 KiB) tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 inet addr:10.8.0.18 P-t-P:10.8.0.17 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:117 errors:0 dropped:0 overruns:0 frame:0 TX packets:15477 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:11534 (11.2 KiB) TX bytes:1157636 (1.1 MiB) # busybox route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.110.183.24 0.0.0.0 255.255.255.252 U 0 0 0 rmnet0 0.0.0.0 10.110.183.25 0.0.0.0 UG 0 0 0 rmnet0 路由新加上了一个,这个就是移动的网络了,但烦人的是,tun0连接依然存在,不知道怎么样将它删掉。 现在终于可以不用重启手机,又可以上网了。 ====== 参考 ====== -http://loneblog.com/linux-deloradd-route.html -http://ohfanfan.javaeye.com/blog/584942