我之前在WSL1下使用Ubuntu工作良好并连接到互联网。
仅通过升级到wsl2,我无法从Bash中ping通google.com。
但是如果我降级到wsl1,则可以ping通。
这里是问题所在:[WSL2] No network · Issue #4731 · microsoft/WSL
我尝试了这个方法,但它不起作用。
步骤1:以管理员身份打开Hyper-V管理器
步骤2:选择操作中的虚拟交换机管理器
步骤3:选择WSL
步骤4:选择外部网络;选择一个适配器并连接到互联网
我的Windows ipconfig
以太网适配器vEthernet(WSL):
Ethernet adapter vEthernet (WSL):
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::30a4:2612:6ee3:2390%142
IPv4 Address. . . . . . . . . . . : 192.168.0.103
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1
从Ubuntu ping 192.168.0.103:
xxxxxxxxx@xxxxxxxxxxx:~$ ping 192.168.0.103
PING 192.168.0.103 (192.168.0.103) 56(84) bytes of data.
From 172.22.131.55 icmp_seq=1 Destination Host Unreachable
From 172.22.131.55 icmp_seq=2 Destination Host Unreachable
Ubuntu 中的 ip route 命令:
xxxxxxxxx@xxxxxxxxxxx:~$ ip route
default via 172.22.128.1 dev eth0
172.22.128.0/20 dev eth0 proto kernel scope link src 172.22.131.55
在Ubuntu上尝试了sudo ip route add default via 192.168.0.103
:
xxxxxxxxx@xxxxxxxxxx:~$ sudo ip route add default via 192.168.0.103
RTNETLINK answers: Network is unreachable