Skip to content

WSL2 localhost forwarding doesn't seem to work #4636

Closed

Description

@impguard
  • 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!

Activity

  1. impguard commented on Nov 4, 2019

    @impguard
    Author
  2. valeryan commented on Nov 9, 2019

    @valeryan

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

  3. craigloewen-msft commented on Nov 15, 2019

    @craigloewen-msft
    Member

    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. :)

  4. impguard commented on Nov 16, 2019

    @impguard
    Author

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

  5. meatherly commented on Dec 19, 2019

    @meatherly

    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

  6. meatherly commented on Dec 19, 2019

    @meatherly

    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.

  7. jameslai commented on Dec 20, 2019

    @jameslai

    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 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.

  8. OctavioBR commented on Dec 20, 2019

    @OctavioBR

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

  9. xanoinc commented on Dec 20, 2019

    @xanoinc

    same here - please fix!

  10. TerrorOnMtHyjal commented on Dec 20, 2019

    @TerrorOnMtHyjal

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

  11. 183 remaining items

  12. mderazon commented on Jun 14, 2021

    @mderazon

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

  13. lculibrk commented on Jul 2, 2021

    @lculibrk

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

  14. mattiagiupponi commented on Jul 6, 2021

    @mattiagiupponi

    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

  15. izzyyhh commented on Sep 12, 2021

    @izzyyhh

    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

  16. cksnsoft commented on Sep 13, 2021

    @cksnsoft

    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

  17. izzyyhh commented on Sep 13, 2021

    @izzyyhh

    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

  18. cksnsoft commented on Sep 13, 2021

    @cksnsoft

    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.

  19. BDisp commented on Oct 11, 2021

    @BDisp

    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.

  20. Gonzih commented on Nov 22, 2021

    @Gonzih

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

  21. barbalex commented on Mar 2, 2022

    @barbalex

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

  22. ronaldndirangu commented on Mar 7, 2022

    @ronaldndirangu

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

  23. rehantoday commented on Jun 26, 2022

    @rehantoday

    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.

  24. sealter commented on Feb 13, 2023

    @sealter

    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

  25. asleepace commented on Jan 31, 2024

    @asleepace

    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
  26. crockeea commented on Feb 15, 2024

    @crockeea

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions