Windows WSL 2 can't ping host machine
I just upgraded to Windows WSL 2 today. The problem is I can't ping the host machine.
I got the IP for the host machine from /etc/resolv.conf.
From WSL 2 Ubuntu console:
- I can ping 8.8.8.8.
- I can not ping 172.17.12.65 (host machine).
- I can not ping www.google.com
Please help, thanks!
Some indication from this github thread suggests that it may be simply the firewall on your Windows host blocking the traffic...
https://github.com/microsoft/WSL/issues/4192#issuecomment-503804455
Quoting xtremeperf:
"Actually... you're probably being blocked by the Windows firewall, as WSL2 is considered to be on a "Public Network". You'll need to open these ports manually on the Windows firewall because they are not yet automatically configured upon installation in this early beta release."
Like harrymc and andoryu- said, check the content of "/etc/resolv.conf" to check the WSL2 IP. AFAIK it should be the one to unblock.
Unfortunately the virtual switch adapter connection profile for WSL2 is "Public" by default, and cannot be set to "Private" permanently unless you can assign a VLAN ID to the adapter, but I don't currently know of way to do that with Microsoft's Virtual Machine Platform feature, which is what I am using. Hopefully Microsoft will allow this to be easily changed in a future release. I haven't yet researched if it is possible to run WSL2 using Microsoft's Hypervisor Platform feature only. If someone knows, that may be helpful.
Although it may not be desirable, you can simply allow inbound ICMP echo traffic on the host firewall for "Public" profiles. An example using Windows Defender:
- Launch Windows Defender Firewall via Control Panel.
- Select "Advanced Settings" (on the left)
- Right-click "Inbound Rules" and choose "New Rule..."
- Choose "Custom" and click "Next"
- Choose "All Programs" and click "Next"
- Select the "ICMPv4" protocol type, then click "Customize..."
- Choose "Specific ICMP types" and check "Echo Request" and click "OK", then "Next"
- Choose "Any IP Address" or add specific addresses as you require for Local and Remote (in your case ), and click "Next"
- Choose "Allow the connection" and click "Next"
- Choose Public, Domain and Private and click "Next"
- Give the rule a meaningful name and click "Finish"
Only answering as I bumped into the same issue.
First, unlikey one comment implied, 172.16.. - 172.31.. is reserved private IP Address, so I'm pretty sure 172.17.12.65 is valid for your host.
I found ipconfig in cmd.exe reveals that nameserver address in /etc/resolv.conf is actually the address of vEthernet(WSL).
Maybe the issue has something to do with hyper-v ethernet adaptor?