作者:Ken張創彬 | 来源:互联网 | 2023-08-21 11:05
几周前,WSL 突然无法访问任何 IP 地址,也无法解析任何域。甚至无法访问内部网络 IP。
>lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
? neofetch
.-/+oossssoo+/-. klewis@NOTEBOOK-KLEWIS
`:+ssssssssssssssssss+:` ----------------------
-+ssssssssssssssssssyyssss+- OS: Ubuntu 20.04.1 LTS on Windows 10 x86_64
.ossssssssssssssssssdMMMNysssso. Kernel: 5.4.72-microsoft-standard-WSL2
/ssssssssssshdmmNNmmyNMMMMhssssss/ Uptime: 1 hour, 20 mins
+ssssssssshmydMMMMMMMNddddyssssssss+ Packages: 1405 (dpkg)
/sssssssshNMMMyhhyyyyhmNMMMNhssssssss/ Shell: zsh 5.8
.ssssssssdMMMNhsssssssssshNMMMdssssssss. Theme: Adwaita [GTK3]
+sssshhhyNMMNyssssssssssssyNMMMysssssss+ Icons: Adwaita [GTK3]
ossyNMMMNyMMhsssssssssssssshmmmhssssssso Terminal: Windows Terminal
ossyNMMMNyMMhsssssssssssssshmmmhssssssso CPU: Intel i7-7820HK (8) @ 2.903GHz
+sssshhhyNMMNyssssssssssssyNMMMysssssss+ Memory: 968MiB / 5942MiB
.ssssssssdMMMNhsssssssssshNMMMdssssssss. Font: Cantarell 11 [GTK3]
/sssssssshNMMMyhhyyyyhdNMMMNhssssssss/
+sssssssssdmydMMMMMMMMddddyssssssss+
/ssssssssssshdmNNNNmyNMMMMhssssss/
.ossssssssssssssssssdMMMNysssso.
-+sssssssssssssssssyyyssss+-
`:+ssssssssssssssssss+:`
.-/+oossssoo+/-.
? ifconfig
? ccat /etc/resolv.conf
nameserver 9.9.9.9
nameserver 8.8.8.8
? ccat /etc/wsl.conf
[user]
default=klewis
# Now make it look like this and save the file when you're done:
[automount]
root = /
optiOns= "metadata"
[network]
generateResolvCOnf= false
? ping 127.0.0.1
ping: connect: Network is unreachable
? ping 192.168.0.1
ping: connect: Network is unreachable
? ping 8.8.8.8
ping: connect: Network is unreachable
? ping google.com
ping: google.com: Temporary failure in name resolution
? nslookup google.com 9.9.9.9
net.c:536: probing sendmsg() with IP_TOS=b8 failed: Network is unreachable
;; connection timed out; no servers could be reached
? ip route
Error: ipv4: FIB table does not exist.
Dump terminated
? ip addr show
1: lo: mtu 65536 qdisc noop state DOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: bond0: mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 86:9a:be:53:f0:44 brd ff:ff:ff:ff:ff:ff
3: dummy0: mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 1e:ff:ad:a4:c4:a7 brd ff:ff:ff:ff:ff:ff
4: sit0@NONE: mtu 1480 qdisc noop state DOWN group default qlen 1000
link/sit 0.0.0.0 brd 0.0.0.0
5: eth0: mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 00:15:5d:b7:f4:da brd ff:ff:ff:ff:ff:ff
C:> ipconfig
Ethernet adapter vEthernet (WSL):
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Hyper-V Virtual Ethernet Adapter #7
Physical Address. . . . . . . . . : 00-15-5D-E5-0C-1B
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::1962:7d4e:a75e:8d62%78(Preferred)
IPv4 Address. . . . . . . . . . . : 192.168.16.1(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.240.0
Default Gateway . . . . . . . . . :
DHCPv6 IAID . . . . . . . . . . . : 1308628317
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-27-B3-1F-34-9C-B6-D0-DD-8C-CF
DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
fec0:0:0:ffff::2%1
fec0:0:0:ffff::3%1
NetBIOS over Tcpip. . . . . . . . : Enabled
>sudo ip route add default via 192.168.16.1
Error: Nexthop has invalid gateway.
我浏览了 GH 并找到了对其他人有用的解决方案。我尝试过的事情:
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
删除 Hyper-V 虚拟适配器并重新启动以让 Windows 重建
将 Hyper-V 虚拟交换机管理器中虚拟交换机的连接位置从内部网络更改为外部网络
确保 %TEMP% 未被压缩
确保 %TEMP% 下没有文件或文件夹被压缩
确保没有防火墙正在运行
https://github.com/microsoft/WSL/issues/4926
https://github.com/microsoft/WSL/issues/4731
关闭生成 resolv.conf 并将网关、9.9.9.9 和 8.8.8.8 添加到 resolv.conf
回答
运行以下命令(并再次访问控制台)为我修复了“网络无法访问”问题
wsl --shutdown