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 是不会通的.

到目前为止,还没有完全弄明白,因为对内核的路由策略不是特别的清楚,如果有哪位大神看到,还望回复给予解答,不胜感激!




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值