Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Localhost connections from Windows to WSL2 have stopped working (presumed docker desktop related) #5606

Closed
rib opened this issue Jul 17, 2020 · 6 comments

Comments

@rib
Copy link

rib commented Jul 17, 2020

Environment

Windows build number: Win32NT             10.0.19041.0 Microsoft Windows NT 10.0.19041.0
Your Distribution version: 18.04
Whether the issue is on WSL 2 and/or WSL 1:  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

Since it's the only thing remotely non-trivial that I did related to my WSL2 setup, I assume that the issue came from installing docker desktop, from here. I have then uninstalled docker desktop to try and resolve this issue (uninstalling hasn't fixed the issue).

E.g. running netcat from WSL2 like this:
nc -l 80

I can no longer connect to the socket from windows (e.g. from firefox) as localhost:80.

I can still connect using the IP address for WSL2 found via ifconfig though this is less convenient.

Expected behavior

Previously I could connect to sockets listening (on 0.0.0.0) within WSL2 from Windows using localhost or the IP 127.0.0.1

Actual behavior

I can now only connect to WSL2 from Windows using the IP address for WSL2 (e.g. found with ifconfig)

@ctataryn
Copy link

@rib unfortunately this is the case for WSL2 networking. When using WSL, it was an actual subsystem of Windows sharing all the same networking. For WSL2, it is actually running Linux within a VM and thus that VM has its very own IP address and networking. If you want to forward ports from your local machine to the container, you can do so like this:

Open an elevated PowerShell or cmd.exe prompt:

  1. Type ipconfig and note the IP address for Ethernet adapter vEthernet (WSL)
  2. To forward port 80 from localhost->WSL type:
netsh interface portproxy add v4tov4 listenport=80 listenaddress=127.0.0.1 connectport=80 connectaddress=<wsl_ip>

Note: it'd probably be wiser to use a different listenport just in case you actually want to run something on 80 within Windows at some point (i.e. 9080 such that you'd connect to http://localhost:9080). You might be scratching your head in the future as to why it doesn't work if you have that portproxy setup, but you had forgotten about it.

To see what portproxies you already have setup:

netsh interface portproxy show all

@rib
Copy link
Author

rib commented Jul 17, 2020

Thanks for the comment @ctataryn

Right, I'm familiar with the general architectural differences between WSL1/2 and can see that it's more fiddly to support routing localhost connections from windows to WSL2 running in a VM but I believe it is intended to be a supported feature of WSL2 (for example please see https://www.bleepingcomputer.com/news/security/wsl2-now-supports-localhost-connections-from-windows-10-apps/)

Connecting to localhost has been working fine with WSL2 up until now so it's not a fundamental limitation of WSL2 - I'm saying something has recently regressed on my system.

The use of port 80 was only as a bare minimal example. In practice I've been serving http using unpriviledged ports.

My current guess is that installing docker desktop had a side effect of deleting whatever bridging/routing tricks were in place beforehand to enable connections to localhost route through to WSL2 - I'm hoping there's some way to fix that.

@denisdifazio
Copy link

Have you tried restarting LxssManager service to see if it starts working again?

@ctataryn
Copy link

@rib wow, I didn't know that. I always was told WSL2 had completely different networking hence the need to port forward. If that's not the case, I hope they figure out a way to make it work the way it was. It's a pain to have to port forward, and it really was a pleasure in the way it used to work under WSL1

@rib
Copy link
Author

rib commented Jul 18, 2020

@denisdifazio I had rebooted so guess the answer was yes. I found it timed out when I tried explicitly restarting the service which also left things in an inconsistent state (couldn't use wsl2).

Since I just rebooted (while I had a pending update) I'm now seeing that WSL2 is working with localhost forwarding working again too - so problem magically solved phew :)

Guess maybe the Windows update fixed something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants