9.2 ICMP、ping 与 traceroute 的证据边界
为了找到请求在哪一跳失踪,你们拿起 ping 和 traceroute,却发现工具输出并不能直接等同于故障结论。
ICMP 是 IP suite 的 control/error-reporting protocol,不是与 IP 平行的“带外通道”。IPv4 ICMP message 装在 IPv4 packet 中(Protocol=1),IPv6 ICMPv6 使用 Next Header=58。它们的 type/code 空间不同,不应把 IPv4 type 直接套到 IPv6。
1. ICMP 报告 network-layer condition,不保证可靠送达
IPv4 常见 message:
| Type | 用途 |
|---|---|
| Echo Request 8 / Echo Reply 0 | ping 的基础 |
| Destination Unreachable 3 | network/host/protocol/port unreachable、fragmentation needed 等,code 决定含义 |
| Redirect 5 | router 建议 host 使用不同 next hop:现代 host/network 常限制接受 |
| Time Exceeded 11 | TTL expired 或 fragment reassembly timeout |
| Parameter Problem 12 | IPv4 header field 有问题 |
ICMP error 带 offending packet 的 header 和足以让 sender 关联 flow 的原 packet data。NAT/firewall/load balancer 处理 ICMP error 时需要解析这个 quoted packet,才能将 error 交给正确 connection。
ICMP 也是 best effort,router 常对它 rate-limit,policy 可丢弃它。“没收到 ICMP error”不证明没有 network error,“收到 unreachable”也要按 type/code 和 quoted flow 解读。
Protocol 还限制哪些 packet 会引发 ICMP error,以避免 error storm:例如不应因一条 ICMP error 再产生另一条 ICMP error,也不对 certain broadcast/multicast/non-initial fragment 生成普通 ICMP error。
2. ping 测的是 Echo path,不是 application health
ping -c 4 192.0.2.10Echo Reply 证明在当前 policy/path/time 下,Echo Request 到达并有 Reply 回来。它不证明:
- TCP 443 可连;
- TLS certificate 正确;
- HTTP application healthy;
- Large packet 与小 Echo packet 走相同 queue/policy;
- Reverse path 和 forward path 相同;
- Packet loss/latency 一直稳定。
Echo timeout 也不证明 host 宕机:firewall 可阻断 Echo,device 可降低 control-plane reply priority,但仍转发 data traffic。所以 ping 是一条 evidence,不是终局 verdict。
3. traceroute 用递增 Hop Limit/TTL 制造 Time Exceeded
Classic Unix UDP traceroute 为 TTL=1、2、3... 发送 UDP probe 到高 destination port:
- 第一 hop 将 TTL 减到 0,丢 packet,回 ICMP Time Exceeded;
- TTL=2 时第二 hop 回 Time Exceeded;
- 到 destination 后,若 UDP port 无 listener,destination 回 ICMP Port Unreachable,trace 结束。
traceroute 192.0.2.10
# Linux 实现常支持 ICMP 或 TCP SYN probe,具体 option 查本机 man page
traceroute -I 192.0.2.10
traceroute -T -p 443 192.0.2.10Windows tracert 默认使用 ICMP Echo,而不是 Unix-style UDP high ports。TCP traceroute 可更接近实际 HTTPS firewall policy,但仍不代替 TLS/HTTP test。
4. Trace 中的 hop 不是完整 topology map
* 可能表示 ICMP reply 被过滤/rate-limit、return path 不通或 probe loss,不一定是该 router 不转发 traffic。Hop address 是回 ICMP 时选的 source address,不一定就是 forward path ingress/egress interface 的可见 address。
ECMP/per-flow hashing 可让不同 five-tuple probe 走不同 path,一行中出现多个 address 可能是 load-balanced path,不是 route 在一次 packet 中来回跳。NAT/MPLS/tunnel 可隐藏 hop,asymmetric routing 让 ICMP reply 走另一条 return path。
为降低 ECMP 造成的假 topology,Paris traceroute 之类方法尽量保持 load-balancing hash input 稳定。即便如此,trace 仍只是某个时刻、某类 probe 的 observation。
5. ICMP 和 PMTUD
IPv4 Fragmentation Needed 与 ICMPv6 Packet Too Big 是 classic PMTUD 的关键 feedback。它们与 traceroute 的 Time Exceeded 不是同一 message。完整 MTU/PMTUD/PLPMTUD 诊断见8.3。
所有 ICMP 都禁止会破坏 PMTUD,尤其对 IPv6。合理 policy 是允许 protocol 正常所需 type/code,做 stateful validation 和 rate limiting,而不是把 ICMP 当作纯粹 attack traffic。
6. 诊断时把多种 probe 放在一起
# DNS / route decision
getent ahosts example.com
ip route get 192.0.2.10
# ICMP evidence
ping -c 4 192.0.2.10
traceroute 192.0.2.10
# Target transport/application evidence
nc -vz -w 3 192.0.2.10 443
curl -v --connect-timeout 3 https://example.com/Commands 取决于 OS/package,对未授权 endpoint 不做 high-rate probing。一个可靠 conclusion 要记录 source network、destination/address family、timestamp、probe type 和 packet capture/counter,而不只贴一张 traceroute screenshot。
7. 验收问题
- 为什么 ICMP 不是 out-of-band protocol?
- Ping 成功能证明什么,不能证明什么?
- UDP、ICMP Echo 和 TCP traceroute 的终止 signal 有何不同?
- Traceroute 一行出现多个 router address 有哪些可能原因?
- 为什么不能为“安全”阻断全部 ICMPv6?
下一课进入9.3 NAT、NAPT 与穿透边界。