除非创建虚拟路由,否则无法访问某个 IP

除非创建虚拟路由,否则无法访问某个 IP

一个主机可以 ping 通除另一个主机之外的所有主机。

假设我的网络中有 4 台主机:

  1. 我的互联网盒子(网关):192.168.0.100
  2. 我的 Ubuntu 机器:192.168.0.1
  3. 我的 RPi 机器:192.168.0.2
  4. 我的涂鸦 WiFi 插头:192.168.0.3

从 Ubuntu 到其他主机的 Ping 操作均正常 从 RPi 到其他主机的 Ping 操作均正常但对于涂鸦插头

尝试 ping 时数据包丢失 100%

pi@hassbian:~ $ ping 192.168.0.3
PING 192.168.0.3 (192.168.0.3) 56(84) bytes of data.
^C
--- 192.168.0.3 ping statistics ---
9 packets transmitted, 0 received, 100% packet loss, time 8339ms

但是,当创建一个像这样的无用路线时

sudo ip route add 192.168.0.3 via 192.168.0.100 dev wlan0

不知何故它正在发挥作用

pi@hassbian:~ $ ping 192.168.0.3
PING 192.168.0.3 (192.168.0.3) 56(84) bytes of data.
64 bytes from 192.168.0.3: icmp_seq=1 ttl=255 time=80.2 ms
From 192.168.0.100 icmp_seq=2 Redirect Host(New nexthop: 192.168.0.3)
64 bytes from 192.168.0.3: icmp_seq=2 ttl=255 time=122 ms
64 bytes from 192.168.0.3: icmp_seq=3 ttl=255 time=144 ms
64 bytes from 192.168.0.3: icmp_seq=4 ttl=255 time=37.9 ms
64 bytes from 192.168.0.3: icmp_seq=6 ttl=255 time=61.1 ms
64 bytes from 192.168.0.3: icmp_seq=7 ttl=255 time=98.8 ms
64 bytes from 192.168.0.3: icmp_seq=8 ttl=255 time=119 ms
64 bytes from 192.168.0.3: icmp_seq=9 ttl=255 time=128 ms
^C
--- 192.168.0.3 ping statistics ---
9 packets transmitted, 8 received, +1 errors, 11.1111% packet loss, time 8040ms

之后,我可以删除该路线,它仍然工作几分钟,然后再次失败。

pi@hassbian:~ $ ip route del 192.168.0.3 via 192.168.0.100 dev wlan0
pi@hassbian:~ $ ping 192.168.0.3
PING 192.168.0.2 (192.168.0.3) 56(84) bytes of data.
64 bytes from 192.168.0.3: icmp_seq=1 ttl=64 time=51.6 ms
64 bytes from 192.168.0.3: icmp_seq=2 ttl=64 time=54.6 ms
64 bytes from 192.168.0.3: icmp_seq=3 ttl=64 time=8.64 ms
64 bytes from 192.168.0.3: icmp_seq=4 ttl=64 time=32.5 ms
^C
--- 192.168.0.3 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3006ms

RPi 正在运行 Pi-Hole,但禁用甚至删除它都无法解决问题。

pi@hassbian:~ $ nslookup 192.168.0.3
3.0.168.192.in-addr.arpa       name = bf3961a448a2979f55sean.lan.

运行 tshark 确认请求已发送但未收到回复

pi@hassbian:~ $ sudo tshark -i wlan0 -f "host 192.168.0.3" -f "icmp"
Running as user "root" and group "root". This could be dangerous.
Capturing on 'wlan0'
    1 0.000000000 192.168.0.2 → 192.168.0.3 ICMP 98 Echo (ping) request  id=0x1a61, seq=6/1536, ttl=64
    2 1.040043499 192.168.0.2 → 192.168.0.3 ICMP 98 Echo (ping) request  id=0x1a61, seq=7/1792, ttl=64
    3 2.080053454 192.168.0.2 → 192.168.0.3 ICMP 98 Echo (ping) request  id=0x1a61, seq=8/2048, ttl=64
    4 3.120040125 192.168.0.2 → 192.168.0.3 ICMP 98 Echo (ping) request  id=0x1a61, seq=9/2304, ttl=64
    5 4.160030649 192.168.0.2 → 192.168.0.3 ICMP 98 Echo (ping) request  id=0x1a61, seq=10/2560, ttl=64
    6 5.200063827 192.168.0.2 → 192.168.0.3 ICMP 98 Echo (ping) request  id=0x1a61, seq=11/2816, ttl=64
    7 6.240062420 192.168.0.2 → 192.168.0.3 ICMP 98 Echo (ping) request  id=0x1a61, seq=12/3072, ttl=64
    8 7.280055125 192.168.0.2 → 192.168.0.3 ICMP 98 Echo (ping) request  id=0x1a61, seq=13/3328, ttl=64
    9 8.320066109 192.168.0.2 → 192.168.0.3 ICMP 98 Echo (ping) request  id=0x1a61, seq=14/3584, ttl=64
   10 9.360099540 192.168.0.2 → 192.168.0.3 ICMP 98 Echo (ping) request  id=0x1a61, seq=15/3840, ttl=64

当然,没有防火墙参与,一切都通过 WiFi 直接连接到网关(也是 DNS 服务器)。

为了完整性,以下是一些附加信息:

添加虚拟路由之前的路由表

pi@hassbian:~ $ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.100   0.0.0.0         UG    600    0        0 wlan0
192.168.0.0     0.0.0.0         255.255.255.0   U     600    0        0 wlan0

arp表

pi@hassbian:~ $ arp | grep fc:67:1f:cb:12:58
bf3961a448a2979f55sean.lan.                ether   fc:67:1f:cb:12:58   C                     wlan0

所以我做了一个非常糟糕的解决方法:我为 root 创建了一个 cron 条目,如下所示

* * * * * ip route add 192.168.0.3 via 192.168.0.100 dev wlan0 >/dev/null 2>&1;ping -c 5 192.168.0.3 >/dev/null 2>&1;ip route del 192.168.0.3 via 192.168.0.100 dev wlan0 >/dev/null 2>&1;ping -c 5 192.168.0.3 >/dev/null 2>&1

Tuya 插头保持可达,我可以使用一些 python 来读取电源信息。

有人能帮我理解为什么这个 RPi 主机 (192.168.0.2) 在访问插头 (192.168.0.3) 时表现如此,而同一网络上的其他主机可以毫无问题地 ping 该插头吗?

我绝望了,我已经没有主意了。我想删除这个 cron 条目并保持稳定的网络状态。

相关内容