Host cannot connect to localhost:5004 when using mirrored networking mode
Windows Version
Microsoft Windows [Version 10.0.26100.3775]
WSL Version
2.4.11.0
Are you using WSL 1 or WSL 2?
- [x] WSL 2
- [ ] WSL 1
Kernel Version
5.15.167.4-1
Distro Version
Ubuntu 24.04
Other Software
If WSL is in Mirrored mode then a server that binds to port 5004 in WSL cannot be reached from the host. If WSL is in NAT mode, this works fine.
Other ports, such as 5003 or 5005 work fine.
Unlike https://github.com/microsoft/WSL/issues/12344 and https://github.com/microsoft/WSL/issues/12122 I am not attempting to use multicast.
Repro Steps
- Run
python3 -m http.server 5004 --bind 0.0.0.0inside WSL - Run
curl http://localhost:5004/from the host
If WSL is in NAT mode, this works. If WSL is in Mirrored mode the command fails with curl: (7) Failed to connect to localhost port 5004 after 2250 ms: Could not connect to server.
This is reproducible 100% of the time. Restarting WSL, rebooting Windows and disabling the firewall does not help.
Expected Behavior
The host should be able to reach the server.
Actual Behavior
The host cannot connect to the server.
Diagnostic Logs
Diagnostic information
Multiple log files found, using: https://github.com/user-attachments/files/20147016/WslNetworkingLogs-2025-05-11_00-13-39.zip
.wslconfig found
Detected appx version: 2.4.11.0
optional-components.txt not found
Diagnostic information
Multiple log files found, using: https://github.com/user-attachments/files/20147016/WslNetworkingLogs-2025-05-11_00-13-39.zip
.wslconfig found
Detected appx version: 2.4.11.0
optional-components.txt not found
Diagnostic information
Multiple log files found, using: https://github.com/user-attachments/files/20147016/WslNetworkingLogs-2025-05-11_00-13-39.zip
.wslconfig found
Detected appx version: 2.4.11.0
optional-components.txt not found
do you have activated the experimental loopback?
Check your .wslconfig and try to add it
[experimental]
hostAddressLoopback=true
@borjamunozf I just tested it. The problem exists regardless of whether hostAddressLoopback is true or false.
I can reproduce the behaviour with and without the hostAdressLoopback, disabling firewall & so.
Linux (Ubuntu 22)
python3 -m http.server 5004
Windows:
- 127.0.0.1:5004 / localhost:5004 not reachable
Changing to 5003 works.
Even using the experimental option ignoredPorts to 5004 the behaviour is the same. Also checked the ports listening Windows side and I don't observe anything using 5004.
Update. I don't recall to see this section before in the Troubleshooting, but it seems that the port 5004 (RTP) won't forward the traffic in these ports to the WSL VM.
Although I didn't mention it in the original description, the bug I personally ran into was in the opposite direction. Meaning, if a Windows service (k3s in my case) is listening on host port 5004, WSL (nodes inside the cluster) cannot reach it either. This doesn't seem to be covered explicitly by the above troubleshooting note but it makes sense that maybe the same problem exists there.
Can anyone shed some light on why these ports are not being forwarded and whether there are plans to fix it? Thank you,