You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WSL2 localhost forwarding doesn't seem to work #4636
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!
Reacted by FallenMax, Rene Vallecillo V, Avi Nerenberg, Tom Stein, Soberia, Brayden C, Loïc Bourg, v-dale, Sandipan, Wesley Abbenhuis and 59 more
Reacted by gabe deko, Yves Chevallier, Dmitry Krokhin, MikeDeri, Avi Nerenberg, Mattia Paterna, Loïc Bourg, Mizunashi Mana, Соснин Алексей, Haitam BOUKAA and 10 more
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. :)
Reacted by Tan Ng, Hamza Basrai, 张翔宇, Octávio Richter, Verdana Mu, Nicholas Newell, Andrei Filippov, Talal Siddiqui, Tony Narlock, Michael Chiche and 11 more
Reacted by Octávio Richter, Nicholas Newell and nimaipatel
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.
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.
Reacted by Octávio Richter, Barne Jürgensen, Testbed Playground, Andrei Filippov, Aaron B, Simen, Rikki Tooley, Philipp Bucher, Aljaž Pungerčar, Goel Biju and 30 more
Same! Went to bed with a functioning localhost:3000 and woke up without.
Reacted by derese.getachew, NkosenhleDuma, Antoine Drouhin, Alberto Pérez de Rada Fiol, nimaipatel, Soberia, Rafael Beck, Rankovski Gorgi, Saurav M H, Amit Digga and 68 more
Reacted by Sayan Naskar, Соснин Алексей, Genoud Magloire, Amine RACHYD, Hayden, gocs, Alek Tobias, Sergey Rykov, dhiazfathra, Equim and 24 more
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
Reacted by Aldayr Ruiz (xSmaky), Cody A. Taylor, RodrigoCMoraes and MiliDurasovic
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.
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.
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
Colin (@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.
Activity
impguard commentedon Nov 4, 2019
valeryan commentedon 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 commentedon Nov 15, 2019
Kevin Wu (@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 commentedon Nov 16, 2019
Yes, it worked since the latest set of builds. Thanks!
meatherly commentedon Dec 19, 2019
This started happening to me recently. I'm currently running:
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 commentedon Dec 19, 2019
When I run
nc -lk 0.0.0.0 3000 | bashI get no activity when I try to connect to it using chrome on the windows side.jameslai commentedon Dec 20, 2019
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 Michael Eatherly (@meatherly) pointed out:
nc -lk 0.0.0.0 3000Attempt 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
ifconfigand looking for the IP assigned toeth0(depending on your setup). Using that, go back into your browser at[ipaddress]:3000. You'll see thenccommand now reports activity.It appears the localhost binding between WSL2 and the host OS broke in the most recent release.
OctavioBR commentedon Dec 20, 2019
Updated to
OS Build 19536.1000yesterday, and the localhost binding broke to me tooxanoinc commentedon Dec 20, 2019
same here - please fix!
TerrorOnMtHyjal commentedon Dec 20, 2019
Same! Went to bed with a functioning localhost:3000 and woke up without.
183 remaining items
mderazon commentedon Jun 14, 2021
In my case, Docker Desktop installed was causing the issue. After uninstalling it, it worked.
lculibrk commentedon Jul 2, 2021
I'm having the same issue after upgrading to WSL2 and installing docker desktop. None of the above solutions worked.
mattiagiupponi commentedon Jul 6, 2021
The only solution that works for me is to run
ipconfig /flushdnsfrom windows terminal and then restart the computer. Try with it, is a workaround but should worksizzyyhh commentedon 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
cksnsoft commentedon Sep 13, 2021
worked for me
izzyyhh commentedon Sep 13, 2021
and the fix remains after restarting your pc? for me it doesn't
cksnsoft commentedon Sep 13, 2021
Izzy Halili (@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 commentedon Oct 11, 2021
Sometimes works and sometimes not after Windows restart.
After uninstall Docker the issue still persists. It works for you by lucking.
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 commentedon Nov 22, 2021
I had this issue and to my surprise closing off my vpn app (privacyinternetaccess) solved the issue.
barbalex commentedon Mar 2, 2022
I suddenly have this issue. And nothing mentioned above has helped so far 😢
ronaldndirangu commentedon Mar 7, 2022
I am currently experiencing this issue too and none of the solutions above work for me.
rehantoday commentedon Jun 26, 2022
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 commentedon Feb 13, 2023
worked for me, so thanks
asleepace commentedon Jan 31, 2024
What worked for me was editing my
.wslconfigfile and commenting out the following:localhostforwarding=truenetworkingMode=mirroredhostAddressLoopback=trueThen running the following from PowerShell
Here is my full configuration
crockeea commentedon Feb 15, 2024
Colin (@asleepace) I'm here because I'm also experiencing the issue. Like you, I have concluded that
networkingMode=mirroredseems to be a contributing factor. Unfortunately, we will need to open a new issue to get this fixed.