Navigation Menu

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

WSL2 localhost forwarding doesn't seem to work #4636

Closed
impguard opened this issue Nov 2, 2019 · 209 comments
Closed

WSL2 localhost forwarding doesn't seem to work #4636

impguard opened this issue Nov 2, 2019 · 209 comments
Labels

Comments

@impguard
Copy link

impguard commented Nov 2, 2019

  • Your Windows build number: Microsoft Windows [Version 10.0.19008.1000]

  • What you're doing and what's happening:

Running Ubuntu 18.04 with WSL 2 enabled. For example running in Powershell

PS C:\Users> wsl --list --verbose
  NAME            STATE           VERSION
* Ubuntu-18.04    Running         2

Within a terminal for WSL2, I run a simple python HTTP server

❯  python -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

Then, trying to access the server from chrome within windows at localhost:8000. I get a "site could not be reached error"

  • What's wrong / what should be happening instead:

I believe it should be working since WSL2 supports forwarding. Unfortunately, I'm not familiar enough with the netstack between windows + WSL2 to diagnose. Let me know if I can provide more info. Thanks!

@impguard
Copy link
Author

impguard commented Nov 4, 2019 via email

@valeryan
Copy link

valeryan commented Nov 9, 2019

recently chrome added a change that forces all traffic to https. Try accessing localhost in firefox or setup ssl in your webserver for localhost.

@craigloewen-msft
Copy link
Member

@impguard localhost now works for you right?

We also added in some more improvements in build 19018, so if you're still experiencing the issue please upgrade and let us know if that resolves it. :)

@impguard
Copy link
Author

Yes, it worked since the latest set of builds. Thanks!

@meatherly
Copy link

meatherly commented Dec 19, 2019

This started happening to me recently. I'm currently running:

Windows 10 Insider Preview 19536.1000 (rs_prerelease)

I don't know why but vscode and wsl2 are having networking problems. When I get one working the other stops. 😢

microsoft/vscode-remote-release#2060

@meatherly
Copy link

When I run nc -lk 0.0.0.0 3000 | bash I get no activity when I try to connect to it using chrome on the windows side.

@jameslai
Copy link

Can confirm running on the latest Windows 10 Insider Preview 18536.1000 broke the localhost binding between WSL2 and the host. This was previously working for me before.

To reproduce:

On your WSL2 machine, as @meatherly pointed out:
nc -lk 0.0.0.0 3000

Attempt to access that machine using your favorite browser on your host Windows OS at localhost:3000, you'll see no activity.

Then, determine the WSL2 IP, which will generally be visible using ifconfig and looking for the IP assigned to eth0 (depending on your setup). Using that, go back into your browser at [ipaddress]:3000. You'll see the nc command now reports activity.

It appears the localhost binding between WSL2 and the host OS broke in the most recent release.

@OctavioBR
Copy link

Updated to OS Build 19536.1000 yesterday, and the localhost binding broke to me too

@xanoinc
Copy link

xanoinc commented Dec 20, 2019

same here - please fix!

@TerrorOnMtHyjal
Copy link

Same! Went to bed with a functioning localhost:3000 and woke up without.

@xanoinc
Copy link

xanoinc commented Dec 21, 2019

looks like this is the issue - #4769

@benhillis
Copy link
Member

@seanmetrix - indeed, fix is inbound.

@talalsiddiqui
Copy link

Please fix this. If Chrome or Firefox runs localhost:3000 successfully, but VS-Code got issues in connectivity. and vice versa.

@takasoft
Copy link

Seems like this problem is solved on OS build 19041.1

@talalsiddiqui
Copy link

talalsiddiqui commented Dec 29, 2019

Right now i have this build. and i am facing issue in this build. This is the latest build so far i guess.
image

@takasoft
Copy link

takasoft commented Dec 29, 2019

@talalsiddiqui Try to change your Insider settings to "Release Preview" and do Windows Update. That's what I'm using.

@talalsiddiqui
Copy link

talalsiddiqui commented Dec 29, 2019

I have set my settings to FAST, plus now i changed to Preview Settings and click updates. there are no updates.
plus if i go back from updates to windows insider, it doesn't show me SELECTED SETTINGS. somehow it is not updating my settings to Preview

@talalsiddiqui
Copy link

Do you know how i can go back to build 19041.

@tony
Copy link

tony commented Dec 30, 2019

I am in build 19536 and have to restart WSL 2 via powershell.

localhost URLs will stop working

Earlier builds work.

@frct1
Copy link

frct1 commented Jan 3, 2020

19041 build. Localhost broken (switched to wsl2 to fix folder rename trouble, but there is another serious thing...)

@gabedeko
Copy link

gabedeko commented Jan 3, 2020

I thought I was tripping. Glad I'm not the only one with this issue.

Any word on a fix release?

@benhillis
Copy link
Member

Regressed recently, tracking with #4769

@fillipefeitosa
Copy link

fillipefeitosa commented Jan 15, 2020

I confirm that localhost:3000 (a meteorjs dev service) does not work on google chrome as @valeryan mentioned.
build 19541
Firefox work as expected.

@ThreshHNS
Copy link

build 19541. Localhost does not work on Chromium.

@arthursoas
Copy link

I think a network reset followed by a reboot worked for me.
image
( Settings > Network & Internet > Network Reset )

Thank you a lot, worked for me too

@stevenobird
Copy link

stevenobird commented Feb 22, 2021

I think a network reset followed by a reboot worked for me.
image
( Settings > Network & Internet > Network Reset )

Thank you a lot, worked for me too

Did it work without any issues after that reset, or did the issues appear again after a while?

@arthursoas
Copy link

I think a network reset followed by a reboot worked for me.
image
( Settings > Network & Internet > Network Reset )

Thank you a lot, worked for me too

Did it work without any issues after that reset, or did the issues appear again after a while?

I had no issues after resetting my network once

@Pho3nixHun
Copy link

Just as a bit more info on this. I encountered this issue after an update of VSCode Insiders Preview (1.55.0), then I switched to the normal VSCode (1.54.3) and the issue was gone. At least until today, when after a restart it appeared again (this was also after happened after VSCode updated itself) and fortunately a network reset solved my issue, but the issue might be caused by VSCode packages on the VM.

@matiasturunen2
Copy link

This is a strange issue. For me it happens roughly on every second boot of my computer. When it happens, usually I just need to restart my pc and it returns to normal.
I'm using Windows version 20H2, build 19042.867, Ubuntu 20.04

@micskeil
Copy link

For me, nothing helped, but turning off "IP Helper" service in Windows.

@alebairos
Copy link

To show addresses and ports configured in portproxy:

netsh interface portproxy show v4tov4

To reset portproxy config(if you saw above a list of addresses and ports it now will be deleted)

netsh interface portproxy reset

In my case, I had a few entries forwarding 0.0.0.0 to the old wsl2 IP(previous attempts). Obviously, nothing worked except calling the new IP directly.

My remaining problem is to make my external IP get forwarded to the wsl2 IP. I managed to make it work with the windows installation configuring my router. But the same does not work for the WSL2 internal IP.

OS Name: Microsoft Windows 10 Pro
OS Version: 10.0.21359 N/A Build 21359

@matiasturunen2
Copy link

As a reply to myself and others looking to solve this issue. For me the solution was to turn off fast startup on windows. https://www.tenforums.com/tutorials/4189-turn-off-fast-startup-windows-10-a.html

@spyro2000
Copy link

spyro2000 commented May 5, 2021

I'm on 20H2 and can't connect from inside WSL2 to services running on the windows host. When I try to to a curl to localhost:8080 it just says connection refused. I already deactivated fast startup.

@ghost
Copy link

ghost commented May 9, 2021

I have not seen this problem for a long time but it started again two days or so ago. I always have the problem after oppening the ubuntu. I am using wsl2 on windows 2004 1941.928. isn't there any permenent solution to this issue yet?

@dolorain
Copy link

if you used proxy software, close any retry it.
if you still cant open it , reset your network and checkout your windows proxy setting, and pac setting to make sure it in default settings.

@mderazon
Copy link

mderazon commented Jun 14, 2021

In my case, Docker Desktop installed was causing the issue. After uninstalling it, it worked.

@lculibrk
Copy link

lculibrk commented Jul 2, 2021

I'm having the same issue after upgrading to WSL2 and installing docker desktop. None of the above solutions worked.

@mattiagiupponi
Copy link

I'm having the same issue after upgrading to WSL2 and installing docker desktop. None of the above solutions worked.

The only solution that works for me is to run ipconfig /flushdns from windows terminal and then restart the computer. Try with it, is a workaround but should works

@izzyyhh
Copy link

izzyyhh commented Sep 12, 2021

nothing works for me, have to run my app on 0.0.0.0 and access it through the Ip adress of the WSL 2 instance

@fmzad
Copy link

fmzad commented Sep 13, 2021

Here, only works after wsl --shutdown

* Ubuntu 20.04

* Version 2004

* S.O compilation 19041.630

today I have the same issue and after wsl --shutdown work again

worked for me

@izzyyhh
Copy link

izzyyhh commented Sep 13, 2021

Here, only works after wsl --shutdown

  • Ubuntu 20.04
  • Version 2004
  • S.O compilation 19041.630

today I have the same issue and after wsl --shutdown work again

worked for me

and the fix remains after restarting your pc? for me it doesn't

@fmzad
Copy link

fmzad commented Sep 13, 2021

@izzyyhh yes it does for me. I am using ubuntu.
I think the problem varies slightly user by user. I'm sorry I can't help you further.

@BDisp
Copy link

BDisp commented Oct 11, 2021

The only solution that works for me is to run ipconfig /flushdns from windows terminal and then restart the computer. Try with it, is a workaround but should works

Sometimes works and sometimes not after Windows restart.

In my case, Docker Desktop installed was causing the issue. After uninstalling it, it worked.

After uninstall Docker the issue still persists. It works for you by lucking.

Here, only works after wsl --shutdown

This was the only solution that worked to me, before restart and even after restart Windows. After running wsl --shutdown command the Docker notify that the WSL 2 backend is stopped and ask if I want to restart it. After Docker restarting the WSL 2 backend, localhost forwarding started working again. Looks like Docker is initializing WSL2 with the right gateway subnet mask.

@Gonzih
Copy link

Gonzih commented Nov 22, 2021

I had this issue and to my surprise closing off my vpn app (privacyinternetaccess) solved the issue.

@barbalex
Copy link

barbalex commented Mar 2, 2022

I suddenly have this issue. And nothing mentioned above has helped so far 😢

@ronaldndirangu
Copy link

I am currently experiencing this issue too and none of the solutions above work for me.

@rehantoday
Copy link

To show addresses and ports configured in portproxy:

netsh interface portproxy show v4tov4

To reset portproxy config(if you saw above a list of addresses and ports it now will be deleted)

netsh interface portproxy reset

In my case, I had a few entries forwarding 0.0.0.0 to the old wsl2 IP(previous attempts). Obviously, nothing worked except calling the new IP directly.

My remaining problem is to make my external IP get forwarded to the wsl2 IP. I managed to make it work with the windows installation configuring my router. But the same does not work for the WSL2 internal IP.

OS Name: Microsoft Windows 10 Pro OS Version: 10.0.21359 N/A Build 21359

This worked for me !!
I tried resetting the network but to no avail.
But found out that 0.0.0.0 was in use by some unknown program. So, I terminated it and voila.

@sealter
Copy link

sealter commented Feb 13, 2023

I think a network reset followed by a reboot worked for me.
image
( Settings > Network & Internet > Network Reset )

Thank you a lot, worked for me too

Did it work without any issues after that reset, or did the issues appear again after a while?

I had no issues after resetting my network once

worked for me, so thanks

@asleepace
Copy link

What worked for me was editing my .wslconfig file and commenting out the following:

  • localhostforwarding=true
  • networkingMode=mirrored
  • hostAddressLoopback=true

Then running the following from PowerShell

wsl --shutdown

Here is my full configuration

# Settings apply across all Linux distros running on WSL 2
[wsl2]

# (CAUSED ISSUE) Turn on default connection to bind WSL 2 localhost to Windows localhost
# localhostforwarding=true

# (CAUSED ISSUE) Switch networking mode to mirrored
#networkingMode=mirrored
#hostAddressLoopback=true

# Disables nested virtualization
nestedVirtualization=false

# Turns on output console showing contents of dmesg when opening a WSL 2 distro for debugging
debugConsole=true

# Enable experimental features
[experimental]
sparseVhd=true

@crockeea
Copy link

@asleepace I'm here because I'm also experiencing the issue. Like you, I have concluded that networkingMode=mirrored seems to be a contributing factor. Unfortunately, we will need to open a new issue to get this fixed.

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

No branches or pull requests