本文主要是介绍ping失败,如果在路由表main内没有entry,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
这是一个没有完全理解的网络路由问题,现象如下:
[root@localhost ~]# ip a s dev eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 link/ether 00:1e:67:64:ee:b8 brd ff:ff:ff:ff:ff:ff inet 192.168.19.22/24 brd 192.168.19.255 scope global eth1 inet6 fe80::21e:67ff:fe64:eeb8/64 scope link valid_lft forever preferred_lft forever [root@localhost ~]# ip ro s
default via 192.168.19.254 dev eth1 [root@localhost ~]# ip ru s
0: from all lookup 255
32764: from all to 192.168.19.22 lookup HOST
32765: from 192.168.19.22 lookup HOST
32766: from all lookup main
32767: from all lookup default[root@localhost ~]# ip ro s t HOST
192.168.19.0/24 dev eth1 scope link src 192.168.19.22
default via 192.168.19.254 dev eth1[root@localhost ~]# ping 192.168.19.51 -w 5
PING 192.168.19.51 (192.168.19.51) 56(84) bytes of data.--- 192.168.19.51 ping statistics ---
6 packets transmitted, 0 received, 100% packet loss, time 4999ms[root@localhost ~]# ping 192.168.19.51 -I eth1 -w 5
PING 192.168.19.51 (192.168.19.51) from 192.168.19.22 eth1: 56(84) bytes of data.--- 192.168.19.51 ping statistics ---
6 packets transmitted, 0 received, 100% packet loss, time 4999ms
但是如果我增加ping的参数,就可以ping通了,如下:
[root@localhost ~]# ping 192.168.19.51 -I eth1 -w 5 -r -c 3 PING 192.168.19.51 (192.168.19.51) from 192.168.19.22 eth1: 56(84) bytes of data.64 bytes from 192.168.19.51: icmp_seq=1 ttl=64 time=2.20 ms 64 bytes from 192.168.19.51: icmp_seq=2 ttl=64 time=0.226 ms 64 bytes from 192.168.19.51: icmp_seq=3 ttl=64 time=0.437 ms --- 192.168.19.51 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2001ms rtt min/avg/max/mdev = 0.226/0.955/2.204/0.887 ms [root@localhost ~]# ping 192.168.19.51 -I 192.168.19.22 -w 5 -c 3
PING 192.168.19.51 (192.168.19.51) from 192.168.19.22 : 56(84) bytes of data.
64 bytes from 192.168.19.51: icmp_seq=1 ttl=64 time=1.86 ms
64 bytes from 192.168.19.51: icmp_seq=2 ttl=64 time=0.630 ms
64 bytes from 192.168.19.51: icmp_seq=3 ttl=64 time=0.210 ms --- 192.168.19.51 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.210/0.902/1.866/0.702 ms
"-I" 和 "-r"的区别如下:
-I eth1 会调用 setsockopt 设置SO_BINDTODEVICE;
-I 192.168.19.22 会调用bind;
-r 会调用 setsockopt 设置 SO_DONTROUTE;
但是如果我在main路由表内增加entry也是可以ping通的,如下:
[root@localhost ~]# ip ro a 192.168.19.0/24 dev eth1
[root@localhost ~]# ip ro s
192.168.19.0/24 dev eth1 scope link
default via 192.168.19.254 dev eth1
[root@localhost ~]# ping 192.168.19.51 -c 3
PING 192.168.19.51 (192.168.19.51) 56(84) bytes of data.
64 bytes from 192.168.19.51: icmp_seq=1 ttl=64 time=1.99 ms
64 bytes from 192.168.19.51: icmp_seq=2 ttl=64 time=0.207 ms
64 bytes from 192.168.19.51: icmp_seq=3 ttl=64 time=0.435 ms --- 192.168.19.51 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.207/0.879/1.997/0.796 ms
如果main table有路由,或者ping -I address 或者 ping -I interface -r, 都会通过,但是如果仅仅是 ping with -I interface 是不会通的.
到目前为止,还没有完全弄明白,因为对内核的路由策略不是特别的清楚,如果有哪位大神看到,还望回复给予解答,不胜感激!
这篇关于ping失败,如果在路由表main内没有entry的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!