WSL icon indicating copy to clipboard operation
WSL copied to clipboard

Dual-mode IPv6 sockets do not accept IPv4 connections via localhost

Open akihiro opened this issue 9 months ago • 2 comments

Windows Version

Microsoft Windows [Version 10.0.26200.7705]

WSL Version

2.6.3.0

Are you using WSL 1 or WSL 2?

  • [x] WSL 2
  • [ ] WSL 1

Kernel Version

6.6.87.2-1

Distro Version

Fedora Linux 43

Other Software

N/A

Repro Steps

  1. Create a simple HTTP server in Go that listens on :8000 (dual-stack by default)
    // main.go
    package main
    import "net/http"
    func main() { http.ListenAndServe(":8000", nil) }
    
  2. Run the server in WSL2
    go run main.go
    
  3. From the same WSL2 instance, try to connect via IPv4
    curl http://localhost:8000/ -v -4
    
  4. From the same WSL2 instance, try to connect via IPv6
    curl http://localhost:8000/ -v -6
    

Actual curl output

IPv4 connection (FAILS):

$ curl http://localhost:8000/ -v -4
* Host localhost:8000 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying 127.0.0.1:8000...
* connect to 127.0.0.1 port 8000 from 127.0.0.1 port 51042 failed: Connection refused
* Failed to connect to localhost port 8000 after 0 ms: Could not connect to server
* closing connection #0
curl: (7) Failed to connect to localhost port 8000 after 0 ms: Could not connect to server

IPv6 connection (WORKS):

$ curl http://localhost:8000/ -v -6
* Host localhost:8000 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:8000...
* Connected to localhost (::1) port 8000
* using HTTP/1.x
> GET / HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/8.15.0
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 404 Not Found
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Tue, 03 Feb 2026 14:15:18 GMT
< Content-Length: 19
<
404 page not found
* Connection #0 to host localhost left intact

Expected Behavior

On standard Linux, when an IPv6 socket is created without setting IPV6_V6ONLY, it operates in dual-stack mode and accepts connections from both IPv4 and IPv6 clients. IPv4 connections are received as IPv4-mapped IPv6 addresses (e.g., ::ffff:127.0.0.1).

The expected behavior is:

  • 127.0.0.1:8080 → Connection succeeds (mapped to ::ffff:127.0.0.1)
  • [::1]:8080 → Connection succeeds

Actual Behavior

In WSL2, IPv4 connections to a dual-stack socket listening on :: are refused, even when connecting from within the same WSL2 instance.

  • curl -4 http://localhost:8000/ → Connection refused
  • curl -6 http://localhost:8000/ → Connection succeeds (404 is expected, server is working)

Additional Context

This issue is related to #4851 (Localhost relay does not support dual-mode sockets), but demonstrates that the problem also occurs within WSL2 itself (not just Windows-to-WSL communication).

Go's net/http package, when given an address like :8000, creates a dual-stack socket listening on [::] by default. This is standard behavior that works correctly on native Linux systems. Many applications and frameworks (e.g., Node.js, Python's http.server, various web frameworks) use this same pattern to serve both IPv4 and IPv6 clients with a single socket.

Diagnostic Logs

WslLogs-2026-02-03_23-34-10.zip

akihiro avatar Feb 03 '26 14:02 akihiro

Diagnostic information
.wslconfig found
Detected appx version: 2.6.3.0

github-actions[bot] avatar Feb 03 '26 14:02 github-actions[bot]

Reproduced on WSL 2.7.12, kernel 6.18.33.2-microsoft-standard-WSL2, networkingMode=virtioproxy, Ubuntu 24.04.

A plain Python socket bound to :: with IPV6_V6ONLY=0 accepts http://[::1]:3999/ (200) but refuses http://127.0.0.1:3999/ (connection refused) from the same distro. Same behavior from next start, which binds :: by default: curl http://localhost:3000/ returns 200 via ::1, curl http://127.0.0.1:3000/ gets connection refused.

Checked on my box: net.ipv6.bindv6only is 0, IPv6 is enabled on loopback (inet6 ::1/128 present), no proxy env vars set, and IPv4 loopback delivery itself is fine (a socket bound to 127.0.0.1 answers normally). So this is specific to IPv4-mapped delivery into :: sockets, and it happens intra-distro, not just Windows-to-WSL.

Workaround is binding IPv4 explicitly (e.g. next start -H 127.0.0.1). Adding this datapoint since most reports here predate the virtioproxy networking mode.

satyalyadav avatar Sep 07 '26 01:09 satyalyadav