WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Loopback only works on 127.0.0.1

Open kodeclan opened this issue 7 years ago • 4 comments

The 18945 update for Windows allows access to WSL 2 via localhost.

Information regarding the issue:

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

  • What you're doing and what's happening: Loopback works for 127.0.0.1 and localhost only.

  • What's wrong / what should be happening instead: Loopback should work on 127.0.0.x (atleast) and 127.x.x.x (ideally)

I have a few services running that are accessed via nginx (running in WSL 2)and are configured for different loopback addresses (Service 1 on 127.0.1.1, Service 2 on 127.0.2.1 etc.)

This used to work correctly on Windows (earlier days using WAMP and vHosts on Apache) and with WSL 1.

While this does not cripple my workflow per say, I waited for this update since it was mentioned that update would address this issue. Since it works on 127.0.0.1 only (and any domain configured in the Windows hosts files to point to 127.0.0.1, eg localhost), this does not seem to be true loopback.

I'm curious as to how this is implemented. Perhaps there could be a way in which we could configure additional loopback IPs in the existing mechanism

kodeclan avatar Jul 28 '19 17:07 kodeclan

I'm curious as to how this is implemented

The magic is done in System32\lxss\wslhost.exe which acts like a broker between WSL2 side Hyper-V socket and Windows side localhost. In Windows side, the socket (AF_INET) is bind with addr.sin_addr.S_un.S_addr = htonl(INADDR_LOOPBACK). Where INADDR_LOOPBACK = 127.0.0.1

Biswa96 avatar Jul 28 '19 18:07 Biswa96

from wsl2 Ubuntu 20.04 can't ping my loopback address 192.168.0.20 - Destination Host Unreachable is it possible ?

timakamystery avatar Jul 07 '20 13:07 timakamystery

This is definitely an issue for me as well.

I'm using a tool that proxies kubernetes services and binds those to 127.10.0.x loopback IPs (automatically -- unfortunately no way to tell it to bind to specific IPs out of the box). These are accessible within WSL2 via curl but are not accessible from Windows.

This behavior can also be replicated through the following in WSL2:

# trying to access the following from a windows browser fails
netcat -l 127.10.0.5 8080

# trying to access this from a windows browser fails
netcat -l 127.0.0.5 8080

# trying to access this from a windows browser succeeds
netcat -l 127.0.0.1 8080

Currently my work-around is using socat in WSL to forward traffic from127.0.0.1 to WSL 127.10.0.x, port by port, service by service. Not a great experience.

edit: in case anyone is looking for how to do that:

sudo apt install socat
# Listen for TCP traffic on 127.0.0.1:8083 and forward to 127.10.0.2:12345; allows forking to handle multiple HTTP connections (in my use case)
socat TCP-LISTEN:8083,fork,reuseaddr TCP:127.10.0.2:12345

Cpcrook avatar Nov 13 '20 20:11 Cpcrook

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!