linux路由错误?

Bal*_*sár 9 linux routing arp ip-routing

一段时间以来,我一直在努力解决这个不容易重现的问题。我使用的是 linux 内核 v3.1.0,有时路由到几个 IP 地址不起作用。似乎发生的事情是内核没有将数据包发送到网关,而是将目标地址视为本地地址,并尝试通过 ARP 获取其 MAC 地址。

比如现在我当前的IP地址是172.16.1.104/24,网关是172.16.1.254:

# ifconfig eth0 eth0      Link encap:Ethernet  HWaddr 00:1B:63:97:FC:DC
          inet addr:172.16.1.104  Bcast:172.16.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:230772 errors:0 dropped:0 overruns:0 frame:0
          TX packets:171013 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:191879370 (182.9 Mb)  TX bytes:47173253 (44.9 Mb)
          Interrupt:17

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.16.1.254    0.0.0.0         UG    0      0        0 eth0
172.16.1.0      0.0.0.0         255.255.255.0   U     1      0        0 eth0
Run Code Online (Sandbox Code Playgroud)

我可以 ping 几个地址,但不能 172.16.0.59:

# ping -c1 172.16.1.254
PING 172.16.1.254 (172.16.1.254) 56(84) bytes of data.
64 bytes from 172.16.1.254: icmp_seq=1 ttl=64 time=0.383 ms

--- 172.16.1.254 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.383/0.383/0.383/0.000 ms
root@pozsybook:~# ping -c1 172.16.0.1
PING 172.16.0.1 (172.16.0.1) 56(84) bytes of data.
64 bytes from 172.16.0.1: icmp_seq=1 ttl=63 time=5.54 ms

--- 172.16.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 5.545/5.545/5.545/0.000 ms
root@pozsybook:~# ping -c1 172.16.0.2
PING 172.16.0.2 (172.16.0.2) 56(84) bytes of data.
64 bytes from 172.16.0.2: icmp_seq=1 ttl=62 time=7.92 ms

--- 172.16.0.2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 7.925/7.925/7.925/0.000 ms
root@pozsybook:~# ping -c1 172.16.0.59
PING 172.16.0.59 (172.16.0.59) 56(84) bytes of data.
From 172.16.1.104 icmp_seq=1 Destination Host Unreachable

--- 172.16.0.59 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
Run Code Online (Sandbox Code Playgroud)

尝试 ping 172.16.0.59 时,我可以在 tcpdump 中看到发送了 ARP 请求:

# tcpdump -n -i eth0|grep ARP
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
15:25:16.671217 ARP, Request who-has 172.16.0.59 tell 172.16.1.104, length 28
Run Code Online (Sandbox Code Playgroud)

并且 /proc/net/arp 有一个不完整的 172.16.0.59 条目:

# grep 172.16.0.59 /proc/net/arp
172.16.0.59      0x1         0x0         00:00:00:00:00:00     *        eth0
Run Code Online (Sandbox Code Playgroud)

请注意,172.16.0.59从其他计算机从这个LAN访问。

有没有人知道发生了什么?谢谢。

更新:回复以下评论:

  • 除了eth0和lo没有接口
  • 在另一端看不到 ARP 请求,但它应该是这样工作的。主要问题是 ARP 请求甚至不应该首先发送
  • 即使我使用命令“route add -host 172.16.0.59 gw 1​​72.16.1.254 dev eth0”添加显式路由,问题仍然存在

Bal*_*sár 7

这确实是一个 linux 内核错误,可能是从 2.6.39 版本开始。我已将问题发布到 lkml 和 netdev 列表(请参阅https://lkml.org/lkml/2011/11/18/191 上的线程),并且刚刚在http://www的不同 netdev 线程中讨论了该问题.spinics.net/lists/netdev/msg179687.html

当前的解决方案是重新启动或刷新所有路由并等待 10 分钟让 icmp 重定向过期。为了防止再次发生,

echo 0 >/proc/sys/net/ipv4/conf/eth0/accept_redirects
Run Code Online (Sandbox Code Playgroud)

有帮助。