
一段時間以來,我一直在努力解決這個不容易重現的問題。我使用的是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
我可以 ping 通幾個位址,但不能 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
當嘗試 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
/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
請注意,172.16.0.59是其他電腦可從此 LAN 存取。
有人知道發生了什麼事嗎?謝謝。
更新:回覆以下評論:
- 除了 eth0 和 lo 之外沒有其他接口
- ARP 請求在另一端看不到,但它應該是這樣運作的。主要問題是 ARP 請求甚至不應該先發送
- 即使我使用命令“route add -host 172.16.0.59 gw 172.16.1.254 dev eth0”添加明確路由,問題仍然存在
答案1
這確實是一個linux核心bug,可能是從2.6.39版本開始的。我已將問題發佈到 lkml 和 netdev 清單(請參閱以下位置的線程)https://lkml.org/lkml/2011/11/18/191),並且剛剛在不同的 netdev 線程中討論過http://www.spinics.net/lists/netdev/msg179687.html
目前的解決方案是重新啟動或刷新所有路由並等待 10 分鐘以使 icmp 重定向過期。為了防止再次發生,
echo 0 >/proc/sys/net/ipv4/conf/eth0/accept_redirects
有幫助。
答案2
172.16.XX 預設子網路遮罩是 255.255.0.0,您已將其重新配置為 255.255.255.0 。因此,主機 172.16.0.x 和 172.16.1.x 位於不同的子網路中。因此它會嘗試透過預設網關路由它。
將子網路遮罩更改為 255.255.0.0 即可解決問題。
能提供個圖嗎。如果你不能畫出一個網絡,它就無法被修復(老網絡工程師的諺語......由我來說!)。
乾杯,