路由存在的情况下ping提示Destination Host Unreachable

问题现象:ping  xxxx  提示

# ping 121.10.41.62
PING 121.10.41.62 (121.10.41.62) 56(84) bytes of data.
From 14.116.225.5: icmp_seq=2 Destination Host Unreachable

首先要明白  Destination Host Unreachable  代表了什么??

说明了:"没有跟对方建立连接";此链接并非tcp的链接

那怎么排查呢?

1、首先查看路由是否正确有没有;通过netstat -rn  route -nv  ip route 等命令查看 ping 41.62 地址时 需要的路由是否正确

根据路由结果 此时报文应该走默认路由 出去 ;

查看ip neigh arp -nv 默认路由邻居表项存在

2、路由route 以及neigh 都存在 为什么还是出现这个错误呢?

那就只能从头到位排查了:

  •   首先ping  lo 查看tcp/ip 协议栈是否正确
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.033 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.025 ms
  • ping  ethx 接口ip 同一个网段的地址;也能通 说明此时接口设备驱动没问题,报文能发送出去也能收包

Tcp/ip 协议栈  dev 设备驱动都是正常 路由  neighbour 也是正常----怎么还是有问题??

难道是查看的东西 使用的工具有问题?

在回头想一下: ping lo 证明了协议栈没问题  ping dev  说明驱动基本ok;

route -nv 说明有了路由---------有了路由 报文就会从这个路由走吗??

万一是从别的路由走呢???

所以通过ip route get  121.10.41.62  发现其路由 via 是个莫名其妙的地址

同时查看ip neigh 发现有这个莫名其妙的地址对应的 表项;不过此表项为failed;

所以此时就能解释通了:ping 此ip 地址提示Destination Host Unreachable。

报文查找路由的时候出现错误,找到错误的出口路由ip;此时路由出口IP的arp 表项不存在

所以导致了 上述错误!!

那么后续需要处理的问题时---为什么出现上述错误:路由查找错误?

$ip route get 121.10.41.62
121.10.41.62 via 10.16.143.108 dev eth8  src 14.116.225.5 
    cache  ipid 0x0bca rtt 186ms rttvar 144ms ssthresh 51 cwnd 46 reordering 9

这里面有个比较好的工具: ip route get xxx 可以直接查找其对应的路由

相关命令有:

  •  ip route show cache   
  • ip route flush cache
  • ip route list/show
  • ip neigh
  • ip addr
  • ip link

ip 命令和ifconfig route arp 等命令相似并且包含它们的功能---可以好好研究一下

现在来详细看下为什么会提示Destination Host Unreachable;

协议栈封包时 ;ip层报文处理完后,需要填充对应的mac 地址; 所以需要根据目的出口Ip来填充mac,由于出口路由via 是 10.16.143.108 ;

1、发出arp req报文请求此ip 地址对应的mac 地址; 

2、发出arp 请求报文后,等待arp 应答报文,如果超时 就会调用

neigh_timer_handler---->neigh_invalidate--->

neigh->ops->error_report(arp_error_report)

---->dst->ops->link_failure(skb);---->ipv4_link_failure

---->kfree_skb

[752934.081279]  [<ffffffff8151cd99>] ipv4_link_failure+0x1d/0x70
[752934.081281]  [<ffffffff8154436b>] arp_error_report+0x30/0x3c
[752934.081284]  [<ffffffff814dc741>] neigh_invalidate+0x4b/0x7e
[752934.081286]  [<ffffffff814dd2b0>] neigh_timer_handler+0x181/0x258
[752934.081289]  [<ffffffff81054497>] run_timer_softirq+0x16e/0x200
[752934.081292]  [<ffffffff814dd12f>] ? neigh_update+0x3c4/0x3c4

这里主要看下:ipv4_link_failure

static void ipv4_link_failure(struct sk_buff *skb)
{
    struct rtable *rt;

    icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);

    rt = skb_rtable(skb);
    if (rt)
        dst_set_expires(&rt->dst, 0);
}

这也就是: 通过发送icmp报文提示 dest/host unreach

此时 源地址就是arp 发送使用的source ip

ping 10.67.10.173
PING 10.67.10.173 (10.67.10.173) 56(84) bytes of data.
From 10.67.10.174 icmp_seq=1 Destination Host Unreachable
From 10.67.10.174 icmp_seq=5 Destination Host Unreachable
From 10.67.10.174 icmp_seq=6 Destination Host Unreachable
From 10.67.10.174 icmp_seq=7 Destination Host Unreachable
From 10.67.10.174 icmp_seq=11 Destination Host Unreachable
From 10.67.10.174 icmp_seq=12 Destination Host Unreachable
From 10.67.10.174 icmp_seq=13 Destination Host Unreachable
tcpdump  -i lo  icmp -ne 
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 262144 bytes
06:40:42.484220 00:00:00:00:00:00 > 00:00:00:00:00:00, ethertype IPv4 (0x0800), length 126: 10.67.10.174 > 10.67.10.174: ICMP host 10.67.10.173 unreachable, length 92
06:40:45.484218 00:00:00:00:00:00 > 00:00:00:00:00:00, ethertype IPv4 (0x0800), length 126: 10.67.10.174 > 10.67.10.174: ICMP host 10.67.10.173 unreachable, length 92
06:40:45.484226 00:00:00:00:00:00 > 00:00:00:00:00:00, ethertype IPv4 (0x0800), length 126: 10.67.10.174 > 10.67.10.174: ICMP host 10.67.10.173 unreachable, length 92
06:40:48.484220 00:00:00:00:00:00 > 00:00:00:00:00:00, ethertype IPv4 (0x0800), length 126: 10.67.10.174 > 10.67.10.174: ICMP host 10.67.10.173 unreachable, length 92
06:40:51.484219 00:00:00:00:00:00 > 00:00:00:00:00:00, ethertype IPv4 (0x0800), length 126: 10.67.10.174 > 10.67.10.174: ICMP host 10.67.10.173 unreachable, length 92
06:40:51.484225 00:00:00:00:00:00 > 00:00:00:00:00:00, ethertype IPv4 (0x0800), length 126: 10.67.10.174 > 10.67.10.174: ICMP host 10.67.10.173 unreachable, length 92

可以看到 eth1 接口ip 为10.67.10.174 时  去ping 一个不存在主机的ip 10.67.10.173 ;

在lo 接口上抓包;可以看到对应的icmp 报文;

报文如下:

 

也就是 icmp报文中 的控制信息中会带上触发这个icmp报文的原始报文

http代理服务器(3-4-7层代理)-网络事件库公共组件、内核kernel驱动 摄像头驱动 tcpip网络协议栈、netfilter、bridge 好像看过!!!! 但行好事 莫问前程 --身高体重180的胖子
原文地址:https://www.cnblogs.com/codestack/p/14312499.html