![不同網路之間無法 ping 通](https://rvso.com/image/1552772/%E4%B8%8D%E5%90%8C%E7%B6%B2%E8%B7%AF%E4%B9%8B%E9%96%93%E7%84%A1%E6%B3%95%20ping%20%E9%80%9A.png)
我的連接如下: PC/Eth<==> Eth/raspberrypi/WLAN <===> WLAN/RPi-2
問題:
我無法從 RPi-2 ping PC,反之亦然
故障排除:
- PC 可以 ping 通樹莓派乙太網路和樹莓派 WLAN
- RPi-2 可以 ping 樹莓派乙太網路和樹莓派 WLAN
- PC 上的防火牆已停用
- [更新] raspberrypi 沒有回覆 arp 請求!
紀錄:
IP總結- PC.eth = 192.168.137.1
- 樹莓派.eth = 192.168.137.254
- 樹莓派.wlan = 10.1.1.254
- rpi-2.wlan = 10.1.1.4
route print
10.1.1.0 255.255.255.0 Auf Verbindung 192.168.137.1 38
C:\WINDOWS\system32>ping 10.1.1.254
Ping wird ausgeführt für 10.1.1.254 mit 32 Bytes Daten:
Antwort von 10.1.1.254: Bytes=32 Zeit<1ms TTL=64
Antwort von 10.1.1.254: Bytes=32 Zeit<1ms TTL=64
Ethernet-Adapter Ethernet 2:
Verbindungsspezifisches DNS-Suffix:
Verbindungslokale IPv6-Adresse . : fe80::5897:b371:242e:36dc%10
IPv4-Adresse . . . . . . . . . . : 192.168.137.1
Subnetzmaske . . . . . . . . . . : 255.255.255.0
Standardgateway . . . . . . . . . :
C:\WINDOWS\system32>tracert 10.1.1.4
Routenverfolgung zu 10.1.1.4 über maximal 30 Hops
1 DESKTOP-R [192.168.137.1] meldet: Zielhost nicht erreichbar.
樹莓派:
:~ $ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.137.1 0.0.0.0 UG 202 0 0 eth0
10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
192.168.137.0 0.0.0.0 255.255.255.0 U 202 0 0 eth0
pi@raspberrypi:~ $ ping 192.168.137.1
PING 192.168.137.1 (192.168.137.1) 56(84) bytes of data.
64 bytes from 192.168.137.1: icmp_seq=1 ttl=128 time=0.567 ms
64 bytes from 192.168.137.1: icmp_seq=2 ttl=128 time=0.599 ms
^C
--- 192.168.137.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1032ms
rtt min/avg/max/mdev = 0.567/0.583/0.599/0.016 ms
pi@raspberrypi:~ $ ping 10.1.1.4
PING 10.1.1.4 (10.1.1.4) 56(84) bytes of data.
64 bytes from 10.1.1.4: icmp_seq=1 ttl=64 time=7.84 ms
64 bytes from 10.1.1.4: icmp_seq=2 ttl=64 time=23.3 ms
RPi-2
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.1.1.254 0.0.0.0 UG 0 0 0 wlan0
10.1.1.0 0.0.0.0 255.255.255.0 U 0 0 0 wlan0
192.168.137.0 10.1.1.254 255.255.255.0 UG 0 0 0 wlan0
:~ $ ping 192.168.137.254
PING 192.168.137.254 (192.168.137.254) 56(84) bytes of data.
64 bytes from 192.168.137.254: icmp_seq=1 ttl=64 time=521 ms
64 bytes from 192.168.137.254: icmp_seq=2 ttl=64 time=13.9 ms
~ $ traceroute 192.168.137.1
traceroute to 192.168.137.1 (192.168.137.1), 30 hops max, 60 byte packets
1 * * *
2 * * *
3 * * *
4 * * *
更新
raspberrypi 上的 tcpdump 日誌
09:58:35.708389 ARP, Request who-has 10.1.1.4 tell 192.168.137.1, length 46
09:58:36.261002 ARP, Request who-has 10.1.1.4 tell 192.168.137.1, length 46
09:58:37.260683 ARP, Request who-has 10.1.1.4 tell 192.168.137.1, length 46
09:58:38.267982 ARP, Request who-has 10.1.1.4 tell 192.168.137.1, length 46
09:58:39.263476 ARP, Request who-has 10.1.1.4 tell 192.168.137.1, length 46
但它會回覆自己的接口
10:28:12.777650 ARP, Request who-has 10.1.1.254 (b8:27:eb:7e:5b:b5) tell 192.168.137.1, length 46
10:28:12.777945 ARP, Reply 10.1.1.254 is-at b8:27:eb:7e:5b:b5, length 28
此時,我認為 linux 不會回覆 PC 的 ARP 請求(或更具體地說 WLAN0 不會回覆)
答案1
您的電腦需要一個預設網關(標準網關)在它可以到達除其自己的子網之外的任何子網之前進行配置。
您可以在適配器設定視窗或管理員命令提示字元中進行設置,如下所示:
route add 0.0.0.0 mask 0.0.0.0 192.168.137.254
來自 RPi-2 的追蹤路由讓我覺得還有其他問題發生,所以如果這不能完全解決問題,請回報。
答案2
作為解決方法,我在 raspberrypi 的 WLAN0 和 eth0 之間設定了一個橋接器,現在它正在工作。