无法 ping 通网络接口 eth0 和 wwan0

无法 ping 通网络接口 eth0 和 wwan0

设置:linux 配置了 Eth0 和 wwan0 接口。Eth0 连接到以太网,wwan0 通过加密狗连接。两个连接都具有互联网连接。

问题:当我启动设备时,默认路由是 eth0,我也可以 ping eth0。虽然 wwan0 也启动了,但无法通过 eth0 ping 通。如果我断开 eth0,则 ping 可以正常使用 wwan0。现在,如果我再次插入以太网,则无法使用 eth0 ping 通。在我的测试案例中,我需要处理频繁插入以太网和加密狗的情况。

配置文件

eth0      Link encap:Ethernet  HWaddr 70:B3:D5:9A:EF:FC
      inet addr:192.168.2.166  Bcast:192.168.3.255  Mask:255.255.252.0
      inet6 addr: fe80::72b3:d5ff:fe9a:effc%1996138192/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:129768 errors:0 dropped:0 overruns:0 frame:0
      TX packets:61524 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:12669568 (12.0 MiB)  TX bytes:1411543 (1.3 MiB)

wlan0     Link encap:Ethernet  HWaddr 60:F1:89:39:07:8E
          inet addr:192.168.42.1  Bcast:192.168.42.255  Mask:255.255.255.0
          inet6 addr: fe80::62f1:89ff:fe39:78e%1996138192/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2865 errors:0 dropped:0 overruns:0 frame:0
          TX packets:704 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:530933 (518.4 KiB)  TX bytes:152134 (148.5 KiB)

wwan0     Link encap:Ethernet  HWaddr 00:1E:10:1F:00:00
          inet addr:10.166.235.232  Bcast:10.166.235.239  Mask:255.255.255.240
          inet6 addr: fe80::21e:10ff:fe1f:0%1996138192/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:194 errors:0 dropped:0 overruns:0 frame:0
          TX packets:476 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:30622 (29.9 KiB)  TX bytes:40449 (39.5 KiB)

当 eth0 为默认时进行路由

default         192.168.2.1     0.0.0.0         UG    0      0        0 eth0
8.8.8.8         192.168.2.1     255.255.255.255 UGH   0      0        0 eth0
10.166.235.224  *               255.255.255.240 U     0      0        0 wwan0
59.144.127.17   192.168.2.1     255.255.255.255 UGH   0      0        0 eth0
192.168.0.0     *               255.255.252.0   U     0      0        0 eth0
192.168.2.1     *               255.255.255.255 UH    0      0        0 eth0
192.168.42.0    *               255.255.255.0   U     0      0        0 wlan0

此时Ping状态:

# ping -I eth0 -c 3 -W 10 www.google.com
PING www.google.com (172.217.166.36): 56 data bytes
64 bytes from 172.217.166.36: seq=0 ttl=57 time=17.688 ms
64 bytes from 172.217.166.36: seq=1 ttl=57 time=16.523 ms
64 bytes from 172.217.166.36: seq=2 ttl=57 time=16.279 ms

--- www.google.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 16.279/16.830/17.688 ms
# ping -I wwan0 -c 3 -W 10 www.google.com
PING www.google.com (172.217.166.36): 56 data bytes


--- www.google.com ping statistics ---
3 packets transmitted, 0 packets received, 100% packet loss

wwan0 的跟踪路由

# traceroute -i wwan0 www.google.com
traceroute to www.google.com (172.217.166.36), 30 hops max, 38 byte packets
 1  local (10.166.235.232)  2996.178 ms !H  2995.670 ms !H  2999.194 ms !H
Here packets are getting dropped at wwan0 interface only.

iptable -L

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere             tcp dpts:0:1023
ACCEPT     udp  --  anywhere             anywhere             udp dpts:0:1023

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  anywhere             192.168.0.0/16
ACCEPT     all  --  192.168.0.0/16       anywhere
ACCEPT     all  --  anywhere             192.168.0.0/16

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

当 wwan0 作为默认路由时,IP 表相同。

简而言之,在两个接口中,我总是只能 ping 默认接口。请帮助我,以便我可以随时 ping 任何接口。

我尝试使用以下方法为 wwan0 添加默认路由

ip route change to default dev wwan0 via 10.166.235.230

但此后我可以通过 wwan0 ping 通,但不能通过 eth0 ping 通。

编辑1

每次我重新插入 eth0 和 wwan0 时,我都可以添加路由来解决这个问题。但现在,我需要为每个接口添加网关以进行路由。不知何故,在我的路由表中,我只能看到一个网关(默认),而看不到另一个。如果我可以为这两个接口获取网关,我可以运行一个脚本,该脚本将在插入/拔出时立即运行,并且可以再次添加路由。请就此提供帮助。

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.2.1     0.0.0.0         UG    0      0        0 eth0
8.8.8.8         192.168.2.1     255.255.255.255 UGH   0      0        0 eth0
**10.177.88.96    *               255.255.255.240 U     0      0        0 wwan0**
59.144.127.17   192.168.2.1     255.255.255.255 UGH   0      0        0 eth0
192.168.0.0     *               255.255.252.0   U     0      0        0 eth0
192.168.2.1     *               255.255.255.255 UH    0      0        0 eth0

相关内容