解决WSL上不了网以及不能通过wsl网络ping通主机
WSL上不了网
在更换电脑无线网络之后,发现wsl上不了网,ssh显示no route,ping baidu.com ping不通,但是ip a显示正常。
因为WSL是相当于一个虚拟机,宿主机给WSL提供的网络支持,在打开宿主机的pwershell后,输入ipconfig,发现WSL的网路显示媒体已断开连接,所以问题是出在宿主机的网络上面,这里对于宿主机的网络进行重置,参考https://www.jianshu.com/p/2b5f850f9e49
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
- 1
- 2
- 3
- 4
之后重启电脑,powershell显示WSL网络正常
WSL成功上网
WSL不能ping通主机
查看宿主机ip
cat /etc/resolv.conf
- 1
查看本地ip
ip a |grep "global eth0"
- 1
在找到ip之后还是ping不通主机,这是因为windows防火墙把访问阻止了,参考(https://github.com/microsoft/WSL/issues/4585),可以用如下指令添加防火墙策略
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
- 1
之后应当可以正常ping通