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

发布时间:2025-12-09 11:43:48 浏览次数:2

问题现象: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 iproute等命令查看ping 41.62地址时需要的路由是否正确

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

查看ipneigharp -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 ms64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.025 ms
  • ping ethx接口ip同一个网段的地址;也能通说明此时接口设备驱动没问题,报文能发送出去也能收包

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

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

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

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

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

所以通过iprouteget121.10.41.62 发现其路由via是个莫名其妙的地址

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

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

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

所以导致了上述错误!!

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

$ip route get 121.10.41.62121.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可以直接查找其对应的路由

相关命令有:

  • iprouteshowcache
  • iprouteflushcache
  • iproutelist/show
  • ip neigh
  • ip addr
  • ip link

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

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

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

1、发出arpreq报文请求此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/hostunreach

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

ping 10.67.10.173PING 10.67.10.173 (10.67.10.173) 56(84) bytes of data.From 10.67.10.174 icmp_seq=1 Destination Host UnreachableFrom 10.67.10.174 icmp_seq=5 Destination Host UnreachableFrom 10.67.10.174 icmp_seq=6 Destination Host UnreachableFrom 10.67.10.174 icmp_seq=7 Destination Host UnreachableFrom 10.67.10.174 icmp_seq=11 Destination Host UnreachableFrom 10.67.10.174 icmp_seq=12 Destination Host UnreachableFrom 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 decodelistening on lo, link-type EN10MB (Ethernet), capture size 262144 bytes06: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 9206: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 9206: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 9206: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 9206: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 9206: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报文的原始报文

host unreachable
需要做网站?需要网络推广?欢迎咨询客户经理 13272073477