Mirrored networking IPv6 localhost (and localhost addresses) and hostAddressLoopback (for assigned addresses) not working from host (WSL2)
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 33.7k
- Forks
- 1.8k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 116
Description
### Windows Version
Microsoft Windows [Version 10.0.22631.2787]
### WSL Version
2.0.9.0
### Are you using WSL 1 or WSL 2?
- [X] WSL 2
- [ ] WSL 1
### Kernel Version
5.15.133.1-microsoft-standard-WSL2
### Distro Version
Ubuntu 22.04.2 LTS
### Other Software
_No response_
### Repro Steps
Steps to reproduce:
-------------------
1. Configure WSL with networkMode=mirrored and hostAddressLoopback=true
2. Ensure Windows firewall allows inbound port 8001 (or is turned off)
3. Have a WSL machine available, e.g. Ubuntu
4. Start a WSL Ubuntu window in Windows Terminal
5. Use 'tmux' in Ubuntu as an easy way to get multiple panes, i.e.: tmux
6. Ctrl-B % to split the window vertically
7. Run a simple HTTP server via Python: python3 -m http.server --bind :: 8001
8. Ctrl-B ; to toggle back to the first pane
9. Checks from the WSL machine (works, both IPv4 and IPv6):
a. Check IPv4 access from WSL (works): curl -v4 http://localhost:8001
b. Check IPv6 access from WSL (works): curl -v6 http://localhost:8001
c. Check IPv4 with local IP (works, change IP addresses as per your networking): curl http://192.168.1.174:8001
d. Check IPv6 with local IP (works): curl http://[2407:8800:bc61:1340::899]:8001
10. Check from another machine on the same network (works, both IPv4 and IPv6):
a. Check IPv4 with IP (works): curl http://192.168.1.174:8001
b. Check IPv6 with IP (works): curl http://[2407:8800:bc61:1340::899]:8001
11. Open a second Windows Terminal window with PowerShell, on the Windows host (running WSL)
12. From Windows host, check IPv4 (works):
a. Check IPv4 localhost (works): curl -v4 http://localhost:8001
b. Check IPv4 local address (works): curl http://127.0.0.1:8001
c. Check IPv4 with IP (works): curl http://192.168.1.174:8001
13. From Windows host fails to connect via IPv6 (fails):
a. Check IPv6 localhost (fails): curl -v6 http://localhost:8001
b. Check IPv6 local address (fails): curl -v6 http://[::1]:8001
c. Check IPv6 with IP (fails): curl http://[2407:8800:bc61:1340::899]:8001
14. Error is: curl: (28) Failed to connect to localhost port 8001 after 21048 ms: Couldn't connect to server
Screen shot:
-----------------
* The Python server is in the top right.
* The first four connections are from WSL on IPv4 and IPv6, for local host and local IP addresses (works)
* The next two (from 192.168.1.206 and 2407:...:4d23) are IPv4 and IPv6 from a separate machine on the network (works) -- the calls from the other machine are on the left.
* The next three are connections from the Windows host on IPv4 for -v4 localhost, 127.0.0.1, and the local IP address -- the last of these can be seen in the middle window
* The bottom of the middle window has the three IPv6 failures, from the Windows host to localhost and local IPv6.

### Expected Behavior
What should happen
------------------
IPv6 (and IPv4) connections to localhost and local IP addresses, from the Windows host, should be forwarded to WSL (as are other IPv6 connections).
### Actual Behavior
Issue / what happens
--------------------
1. From Windows host, unable to connect to the WSL localhost port via IPv6, only IPv4 (both work from WSL).
2. From Windows host, unable to connect to the WSL hostAddressLoopback port via IPv6, only IPv4 (both work from WSL and from the network).
| Destination | WSL guest | Windows host | Network
| -- | -- | -- | --
| localhost IPv4 | yes | yes | -
| localhost IPv6 | yes | **FAILS** | -
| 127.0.0.1 (IPv4) | yes | yes | -
| [::] | yes (IPv6) | **FAILS** | -
| IPv4 host address, e.g. 192.168.1.174 | yes | yes (1) | yes
| IPv6 host address, e.g. [2407:8800:bc61:1340::899] | yes | **FAILS** (1) | yes
(1) with hostAddressLoopback; without setting loopback to host address is not available on either v4 or v6 (by design)
This breaks applications trying to explicitly connect to IPv6, e.g. [::1], or that only resolve/try the IPv6 address for 'localhost'.
Error trying to use curl to connect is: curl: (28) Failed to connect to localhost port 8001 after 21048 ms: Couldn't connect to server
Mitigation: Systems that try both IPv6 and IPv4 resolutions of 'localhost' may still work (e.g. a browser with happy eyeballs may try both).
Notes
--------
This also happens with hostAddressLoopback turned off (default), with none of the local IPs working (as expected), i.e. localhost still doesn't work. I turned it on to see if it fixed the issue (it didn't).
The python web server was used as a simple example/reproduction of the forwarding failing for IPv6, with the original issue occurring trying to access a service running in Podman hosted in WSL, i.e. a container, with Podman IPv6 enabled, trying to expose the port, and the IPv4 worked but IPv6 didn't. However the issue had nothing to do with Podman or containers, but can be reproduced as above with a simple HTTP server running on a WSL Ubuntu machine.
### Diagnostic Logs
Failure messages (from Windows host):
---------------------------------------------
(First response is an IPv4 success)
PS C:\Users\Sly> curl http://192.168.1.174:8001
Directory listing for /
Directory listing for /
- .bash_history
- .bash_logout
- .bashrc
- .cache/
- .motd_shown
- .profile
- .python_history
- .sudo_as_admin_successful
PS C:\Users\Sly> curl -v6 http://localhost:8001
* Trying [::1]:8001...
* connect to ::1 port 8001 failed: Timed out
* Failed to connect to localhost port 8001 after 21437 ms: Couldn't connect to server
* Closing connection
curl: (28) Failed to connect to localhost port 8001 after 21437 ms: Couldn't connect to server
PS C:\Users\Sly> curl http://[::1]:8001
curl: (28) Failed to connect to ::1 port 8001 after 21057 ms: Couldn't connect to server
PS C:\Users\Sly> curl http://[2407:8800:bc61:1340::899]:8001
curl: (28) Failed to connect to 2407:8800:bc61:1340::899 port 8001 after 22279 ms: Couldn't connect to server
PS C:\Users\Sly>
Environment:
------------
PS C:\Users\Sly> wsl --version
WSL version: 2.0.9.0
Kernel version: 5.15.133.1-1
WSLg version: 1.0.59
MSRDC version: 1.2.4677
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22631.2787
PS C:\Users\Sly> ipconfig
Windows IP Configuration
Ethernet adapter Ethernet0:
Connection-specific DNS Suffix . : lan
IPv6 Address. . . . . . . . . . . : 2407:8800:bc61:1340::899
IPv6 Address. . . . . . . . . . . : fd7c:e25e:67e8:40::899
IPv6 Address. . . . . . . . . . . : fd7c:e25e:67e8:40:5c3:271c:adcc:4e6b
Temporary IPv6 Address. . . . . . : 2407:8800:bc61:1340:8035:3724:ed35:c20c
IPv6 Address. . . . . . . . . . . : 2407:8800:bc61:1340:e952:3110:2901:7499
Temporary IPv6 Address. . . . . . : fd7c:e25e:67e8:40:8035:3724:ed35:c20c
Link-local IPv6 Address . . . . . : fe80::4d6d:9ea:a521:d435%7
IPv4 Address. . . . . . . . . . . : 192.168.1.174
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
PS C:\Users\Sly> cat .wslconfig
[experimental]
networkingMode=mirrored
hostAddressLoopback=True
On the WSL instance:
sly@VMWIN2023:~$ uname -a
Linux VMWIN2023 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
sly@VMWIN2023:~$ ip addr
1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1492 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:8b:52:b1 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.174/24 brd 192.168.1.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 2407:8800:bc61:1340::899/128 scope global nodad noprefixroute
valid_lft forever preferred_lft forever
inet6 fd7c:e25e:67e8:40:5c3:271c:adcc:4e6b/64 scope global nodad deprecated noprefixroute
valid_lft forever preferred_lft 0sec
inet6 fd7c:e25e:67e8:40:8035:3724:ed35:c20c/128 scope global nodad noprefixroute
valid_lft forever preferred_lft forever
inet6 fd7c:e25e:67e8:40::899/128 scope global nodad noprefixroute
valid_lft forever preferred_lft forever
inet6 fe80::4d6d:9ea:a521:d435/64 scope link nodad noprefixroute
valid_lft forever preferred_lft forever
3: loopback0: mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:15:5d:67:c2:f2 brd ff:ff:ff:ff:ff:ff
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce with WSL 2 using networkMode=mirrored and hostAddressLoopback=true, then run the listed Python HTTP server and curl checks from WSL, the Windows host, and another network machine. Trace the mirrored-networking IPv6 forwarding path; done means the Windows host can reach WSL through IPv6 localhost and assigned IPv6 addresses as IPv4 already does.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- networking, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100