从特定接口 ping 时未收到 ICMP 回复

从特定接口 ping 时未收到 ICMP 回复

我有一台运行 CentOS 的 Linux 机器,有 2 个 ISP。我的翻转 ISP 通道脚本尝试确定当我们在辅助 ISP 通道时,主 ISP 通道是否启动,反之亦然,何时需要从主 ISP 通道更改为辅助 ISP 通道。这是很正常的事。

为此,我想要从现在不是默认网关的接口进行 ping 操作。

我的 2 个 iface 中,eth1 是主要的,eth2 是次要的。

以 eth1 为例,当我们想检查 eth2 上是否有互联网时,Eth2 处于启动状态。

ping -I eth2 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 1.2.3.4 eth2: 56(84) bytes of data.
^C
--- 8.8.8.8 ping statistics ---
15 packets transmitted, 0 received, 100% packet loss, time 14173ms

但是我运行的 tcpdump 显示数据包已发送并传送到服务器,但 ping 实用程序没有发现某些原因。为什么我不知道?可能是什么原因?

tcpdump:

17:36:42.191153 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
    1.2.3.4 > 8.8.8.8: ICMP echo request, id 44138, seq 1, length 64
17:36:42.235899 IP (tos 0x0, ttl 59, id 30465, offset 0, flags [none], proto ICMP (1), length 84)
    8.8.8.8 > 1.2.3.4: ICMP echo reply, id 44138, seq 1, length 64
17:36:43.190616 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
    1.2.3.4 > 8.8.8.8: ICMP echo request, id 44138, seq 2, length 64
17:36:43.235363 IP (tos 0x0, ttl 59, id 31136, offset 0, flags [none], proto ICMP (1), length 84)
    8.8.8.8 > 1.2.3.4: ICMP echo reply, id 44138, seq 2, length 64
17:36:44.190575 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
    1.2.3.4 > 8.8.8.8: ICMP echo request, id 44138, seq 3, length 64
17:36:44.235346 IP (tos 0x0, ttl 59, id 32083, offset 0, flags [none], proto ICMP (1), length 84)
    8.8.8.8 > 1.2.3.4: ICMP echo reply, id 44138, seq 3, length 64
17:36:45.190554 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
    1.2.3.4 > 8.8.8.8: ICMP echo request, id 44138, seq 4, length 64
17:36:45.235368 IP (tos 0x0, ttl 59, id 32355, offset 0, flags [none], proto ICMP (1), length 84)
    8.8.8.8 > 1.2.3.4: ICMP echo reply, id 44138, seq 4, length 64

netstat -rn 显示 eth2 不是默认网关,但它是 eth1。

答案1

生成的 ICMP 数据包ping可能会被路径上过于严谨的防火墙过滤掉。 traceoute 可能帮助定位此类问题。

相关内容