-
Notifications
You must be signed in to change notification settings - Fork 836
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
WSL2 not forwarding ports #5439
Comments
I'm on 20150 and no problem here. VSCode Remote and all ports work like they did prior to the update. I didn't recreate the VM though. Also I'm running Docker Desktop for the web-dev ports. |
Same issue on 19042. I've combed through a lot of similar issues here but no one solution seems to fix it for good (including disabling fast refresh and rebooting Ubuntu with wsl --shutdown). It was working fine for months, then it broke out of nowhere. It randomly works again with some ports, only to stop working altogether minutes later, so it's really hard to reproduce the problem. I've resorted to this for now.
|
There was an port-forwading issue a while back, which was got resolved. Just some thoughts. Did you check your firewall settings? Maybe some third-party interferes there? |
Not a firewall issue for sure. Looking at other open issues it seems like I'm not the only one having this problem still. I apprecciate this sort of thing is pretty complex to debug, so I'm just chiming in to let the devs know it might be worth looking into. Disclosure: I haven't tried reinstalling my distro, but I'm running the standard Ubuntu 18 with Node.js to serve a web server on different ports (300x, 500x, 900x). VS Code is running just fine and so is everything else, I just can't reliably get a web server on Linux to load on Window's localhost. (Yes, it's running on 0.0.0.0). |
Thats for sure. TBH, I'm running everything in Docker containers, NodeJS servers too. This has the benefit that it allows me to test stuff from my smartphone, accessing 192.168.1.100:3000 (Windows PC). And this is a network functionality that WSL2 does not offer, unfortunatelly. Maybe it's somehow correlated. Could you test running the servers inside Docker containers? |
That was my use case as well. I actually managed to get it working before, back when localhost forwarding was working properly by running this on PowerShell as admin:
(I got this snippet to work with this solution, but it works only for one port. Maybe related to this issue, which was closed but other people still report as not working) Worked like a charm with a simple firewall rule on Windows Defender to open those two ports. I might give Docker a go, but honestly I doubt it will work, and if it's indeed a networking issue I'm way out of my depth here. Thank you for your comments though! :) |
Apologies if I'm misunderstanding, but sounds like #4150 (comment) - case where WSL doesn't use Host's IP (with Powershell-script scolution) |
Definitely related, but that wasn't supposed to be needed as of 18945, as evidenced by the fact that it does work by default on newer builds, though unreliably. I might be wrong but I'm under the impression that there are several open issues reporting the same problem in different terms, with multiple fixes that work for at least some people but not for others. From a quick search: @craigloewen-msft mentions in one of those that a similar issue is being tracked here, but with so many open issues and possible solutions there are bound to be other people out there as confused as me. I think what's most troubling is that it seems to randomly stop working after a while, so what seemed like a fix yesterday suddenly doesn't work anymore today. |
I'll check some more ports on Monday to see if it persists for all ports/services; but my issue is specifically that I've uninstalled everything and reinstalled, fresh distro, no restore from backups or anything weird, and it just isn't working. I have no firewalls other than Windows default stuff; no issues or errors reported from antivirus etc. |
Please read the ticket description. Mine was also working fine after the upgrade. It ceased working when I tried to wipe my existing distro and reinstall fresh. The new distro does not map ports. |
Since I have a lot of work going on, I unfortunatelly cannot unregister/reregister, etc. my current distro... but...
I've installed a fresh new kali-distro from the Windows Store, installed NodeJS, run a quick server on port 9070 and |
As usually, I've put my PC in hybernation mode overnight, I tested the NodeJS server after waking up my PC, and it still works. |
Please turn off Fast Startup and restart Windows. If the issue continues at least we can discard bug #5298 |
OK I already had fast boot turned off, so it wasn't that. I went into 'Windows Defender Firewall with Advanced Security', deleted all 'Inbound Rules' for 'node', and now it seems to be working. Though I don't recall getting a firewall prompt for it lately, I guess it must have been that? Even now that it's working, I don't see any entries in Windows Defender firewall Inbound Rules for it though. |
Re-enabled fastboot, still working. Closing this issue - apologies for the concern :) |
I can't get any services such as node js to work unless I run the commands via vscode and then ctrl+click the link from there. If I simply run the command and try accessing in the browser it doesn't work until Ictrl+click the link from vscode first. Is this intentional, ie wsl is dependant on vscode to open ports? or should ports just open when run via terminal without vscode? |
@b-hayes thank you. I had this problem scratching my head for hours. I remember with WSL(1) I never had this problem. But now I could not access my VS Code project running on WSL2 *Ubuntu 20.04). I don't know why this is happening but I guess is some kind of internal port forward that vscode (or node) does on WSL2 ?!?! Hopefully your solution will help others solve their problem temporarily until the actual port that the app is running is working (like it did with WSL1) |
Elaborating on the above comments, starting a service on 0.0.0.0 and doing the left ctrl + click doesn't work. You have to start it on 127.0.0.1 and then do the left Ctrl + click on the URL from the vs code terminal for it to work. And yeah, the ports do show up different when they open in the browser. Looks like there's some automatic mapping going on... |
Same problem
I've launched docker
and I can not access runing container on localhost:5432 I've checked ifconfig inside WSL and tryed IP of eth0: 172.17.129.254 but same no results On loclahost: conneciton refused |
This is the first search result on google. You maybe interested in running this in powershell:
and/or performing a "network reset" as described here: #4636 (comment) Also, make sure you've configured the windows firewall. Windows Start -> search for "advanced" |
What helped in my case was setting the ranges for dynamic ports to a higher range, as described in #5306 (comment) and docker/for-win#3171 (comment) |
This is an intermittent issue for me that re-appeared after the last WSL update. What work for me to fix it was Start -> Settings -> Network & Internet -> Network Reset (blue link) |
I've been around in circles with this and haven't found a single suggestion that helped so thought I should post here what did eventually work. My symptom was that after many requests to a port mapped through docker (wsl2 mode) traffic would just stop with connection refused, closed, reset etc errors on the ipv6 resolved local host (::1) wsl --shutdown reset the problem until more request load retriggers it again, reliably. 127.0.0.1:49153 keeps working while localhost:49153 hangs. I ran
20304 is Docker Desktop Backend which is what is meant to be listening, and why ipv4 works. I killed the offending process matching the id and the problem was fixed. I couldn't reproduce until i shutdown (or restart) the machine. It is possible this is related to the Fast Startup issue, but i have this disabled according to the UI #6162. hope that helps someone stuck on this, maybe even inspire someone on where to look for a permanent fix even? |
Looks like I have very specifically hit this issue, now that I know what I am looking for: |
Periodically I couldn't connect to this port (OS build 19043). How I fix it:
|
This works for me!! Thanks |
I had some issues with the WSL2 port forwarding. I checked all the solutions, turn the hibernate off, etc. What worked for me is using different listenport and connectport in the 'netsh interface portproxy add...' command. |
To prevent rebooting the whole system, you can try: |
Environment
Steps to reproduce
Associated Feedback Hub link: https://aka.ms/AA8qyij
Initially after upgrade to Win 10 20150, my existing WSL2 build was working great.
I unregistered that WSL distro, and on recreating it, I could no longer connect to ports hosted in WSL, from Windows.
I've uninstalled the WSL features (including Containers + Hyper-V etc), and the Ubuntu apps that came from the Microsoft Store, and uninstalled VSCode (the application i'm trying to use primarily)
Reinstalled all these, fresh WSL2 install of Ubuntu 20.04. Installed VSCode + the WSL remote extension, and it installs and starts the VS Code server listening on a particular port; but errors that it cannot connect to it.
This port is accessible from within WSL, but not from Windows (eg. browser etc - it responds with a 404 at least in WSL, but ERR_CONNECTION_REFUSED from a browser in windows.)
Expected behavior
WSL should forward ports of running services, to be accessible from Windows (as per previous behaviour).
Actual behavior
Ports opened in WSL are not accessible from Windows.
lxcore_logs.zip
The text was updated successfully, but these errors were encountered: