WSL: Cannot access Windows network port from WSL2 using virtual IP

Environment

Windows build number: 10.0.19041.0
Your Distribution version: Ubuntu 10.04
Whether the issue is on WSL 2 and/or WSL 1: WSL2 (Linux version 4.19.104-microsoft-standard (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Wed Feb 19 06:37:35 UTC 2020)

Steps to reproduce

I just installed a fresh Ubuntu 20.04 LTS on WSL2 for creating this ticket (I experienced the same problem with my Debian on WSL2, so I downgraded that one back to WSL1 as I needed the functionality).

Make sure to have a webserver running on Windows, and you cannot access it with the IP from /etc/resolv.conf in WSL2, even through that should work according to the docs.

In this case, I created a simply NodeJS server on port 8080, which is listening on 0.0.0.0. It is accessible from the entire LAN on 192.168.1.24 (local IP).

Now, if you want to access it from WSL2, using the nameserver (172.21.48.1 here, or virtual IP) as suggested in the article, it unfortunately does not respond at all. Using localhost doesn’t work either (as expected), but using the direct IP address does work.

Below is a screenshot of my test: top-left is the WSL2 Ubuntu, top-right is Powershell on Windows running the actual server. De two browser windows on the bottom are run on the host machine, demonstrating the webserver responds to both localhost and the external IP (external IP access was also tested from another machine on the LAN, that works fine).

image

Expected behavior

I would expect to either

  • see the virtual IP behave as described in the documentation
  • see the local IP in /etc/resolv.conf (but that breaks DNS resolving at this time)
  • see the local IP in some other file

The latter would be useful for scripting.

Actual behavior

Well, it isn’t working as I would have hoped😄

P.S. While working on this, I also managed to break DNS resolving completely. This was probably related to me resetting the Windows firewall (for testing), as it was fixed after rebooting.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 25
  • Comments: 19

Most upvoted comments

Microsoft, fack you.

Windows was sht, is sht, always will be sh*t

Microsoft, fack you.

This is still an issue as to this day. I tried every possible workaround… The big problem is that this is preventing many people from migrating from Docker for Windows to Podman running inside Linux on WSL 2, as they cant test the services in the containers against an application server running on Windows (which you usually do when developing said server).

Downgrading to WSL 1 is also not an option as this causes issues with Podmans File system drivers

You’re probably being blocked by the Windows firewall as Ethernet is a “Public” network. Create a new rule in windows firewall settings to allow inbound traffic

check out this answer on https://superuser.com/a/1496354

I adden an inbound rule for my test port (8000 in my case) that should apply for all interfaces and for all types of networks (so including public). Still, I can’t access the service from within WSL2 using the IP in /etc/resolv.conf.

I also don’t see dropped connections logged by the Windows firewall.

I also facing similar issues where as sometimes port open from wsl2 accessible from windows host and sometimes not… Didn’t able to get actual reason anywhere… I have all things at latest version on todays date…

still open after two years and no response from Microsoft … what a shame

but i found a workaround for this on Windows 10 using Internet Connection Sharing:

  1. right click your host network adapter -> properties -> sharing -> Allow other network users to … -> choose WSL in dropdown list
  2. you may get a dialog say some warning, click Yes. after this the host can access internet normally but WSL can’t
  3. restart, then WSL can access internet, and host can be access via host network adapter’s IP in step 1

it’s wired the chosen WSL disappear after restart in step 1’s properties dialog, but seems have no impact.

NOTE: turn off windows defender firewall when testing