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

Local server running in wsl2 not available via host #10665

Closed
1 of 2 tasks
henryfoster opened this issue Oct 23, 2023 · 5 comments
Closed
1 of 2 tasks

Local server running in wsl2 not available via host #10665

henryfoster opened this issue Oct 23, 2023 · 5 comments
Labels

Comments

@henryfoster
Copy link

Windows Version

10.0.22621.2428

WSL Version

1.2.5.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.90.1

Distro Version

Ubuntu 22.04

Other Software

No response

Repro Steps

  • start a local webserver in wsl (python, node, php)
  • open a browser on the host and open 127.0.0.1:port

image

Expected Behavior

  • the server running in wsl should be available and serve the page using 127.0.0.1:port

Actual Behavior

  • browser shows a connection error
  • localhost:port works but 127.0.0.1:port does not

Diagnostic Logs

No response

@chanpreetdhanjal
Copy link

Could you please follow the steps below and attach the diagnostic logs? https://github.com/microsoft/WSL/blob/master/CONTRIBUTING.md#collect-wsl-logs-for-networking-issues

@lightify97
Copy link

I'm having the same issue. I have attached my logs.
WslNetworkingLogs-2023-10-28_12-28-11.zip

It was working previously but suddenly stopped. One possible issue might be latest windows update. (KB5031455)

@Canowyrms
Copy link

Canowyrms commented Nov 7, 2023

localhost:port works but 127.0.0.1:port does not

I think WSL resolves localhost to its IPv6 address ([::1]) and the web server is binding to that by default, hence why http://localhost/ works but http://127.0.0.1/ does not. Try it again, but this time, in your browser, try http://[::1]/. Bet that works.

Alternatively, on the host, you can use the following command in PowerShell to check which IP address your web server is bound to:

PS> netstat -ano | findstr ":80"
  TCP    [::1]:80               [::]:0                 LISTENING       17668

If you want your web server on IPv4 (i.e. 127.0.0.1), pass it 127.0.0.1 instead of localhost.

I'm not sure how to bind a simple web server to IPv4 and IPv6 at the same time. I would also like localhost to resolve to its IPv4 and IPv6 address.

@keith-horton
Copy link
Member

Hi there.
Can you verify that you have your webserver listening on 127.0.0.1? The above shows that there's not a socket listening at that address, on that port #. By default, localhost will resolve the IPv6 address first. (Which appears why that works for your setup - since there's an IPv6 loopback listener).

Copy link
Contributor

This issue has been automatically closed since it has not had any activity for the past year. If you're still experiencing this issue please re-file this as a new issue or feature request.

Thank you!

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

6 participants