我使用了一个名为 [WSLAttachSwitch] 的工具(https://github.com/dantmnf/WSLAttachSwitch) 将外部 Hyper-V 交换机连接到 WSL2,因为 Windows 不会将每个 Windows 网络接口都暴露给 WSL2。使用该工具后,将创建一个名为 eth1 的新接口,然后我使用 dhclient 为该接口指定一个 ip:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1488
inet 172.30.20.144 netmask 255.255.240.0 broadcast 172.30.31.255
inet6 fe80::215:5dff:fe28:f770 prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:28:f7:70 txqueuelen 1000 (Ethernet)
RX packets 17 bytes 2593 (2.5 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 15 bytes 1174 (1.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.8 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::215:5dff:fe01:2520 prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:01:25:20 txqueuelen 1000 (Ethernet)
RX packets 11 bytes 2815 (2.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10 bytes 1884 (1.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
问题是我希望能够使用这两个接口。当我想使用 eth1 ping 8.8.8.8(或将此接口用于其他目的)时,它说无法到达目的地。我知道这是一个路由问题,但我不知道如何解决这个问题。
这里还有一些有关路线的信息:
ip route show
default via 172.30.16.1 dev eth0 proto kernel
172.30.16.0/20 dev eth0 proto kernel scope link src 172.30.20.144
192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.8
ip rule show
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
更新 当我使用接口的 IP 地址时,它起作用:
ping -I 192.168.1.8 1.1.1.1
PING 1.1.1.1 (1.1.1.1) from 192.168.1.8 : 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=56 time=106 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=56 time=19.6 ms
64 bytes from 1.1.1.1: icmp_seq=3 ttl=56 time=19.0 ms