WSL: Can't access UDP services running in WSL on localhost

Version

Microsoft Windows [Version 10.0.19043.1889]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

5.10.102.1

Distro Version

Debian 11

Other Software

No response

Repro Steps

start a UDP service in WSL, like nc:

nc -ul 5000

talk to that service from host, since windows doesn’t come with nc, I’m actually using nc from msys2:

nc -u 127.0.0.1 5000

and type something in nc and press enter.

Expected Behavior

We should be able to access that service on localhost, like when we type something in nc and press enter, the same thing should show on the other side.

As the document says so: https://docs.microsoft.com/en-us/windows/wsl/networking#accessing-linux-networking-apps-from-windows-localhost

Actual Behavior

We can’t.

Diagnostic Logs

  • if we remove -u thus let nc listen on TCP, it will work.
  • if we replace 127.0.0.1 with WSL’s actual address(172…), it will work.

My conclusion is that WSL is not forwarding UDP, which is inconsistent with the document.

There seems to be similar issue reports, but they are too specific, this is actually a more generic and broad issue. https://github.com/microsoft/WSL/issues/6351

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 17
  • Comments: 20

Most upvoted comments

This has caused me headache while trying to connect from windows to containers that bind to UDP ports running in WSL. I have tried the suggestions above but none of them work.

I am quite shocked that basic UDP communication is not functional.

Not a real fix, but a workaround: From WSL2, run the ifconfig command. Take whatever inet IP address the eth0 interface is set to use, and try connecting to that IP:<your_port>. You just can’t use localhost or 127.0.0.1 with UDP for some reason!

Actually, I just got it working! Works fine after turning hostAddressLoopback to true. Pretty much flawless UDP communication now!

I ran into the same problem to forward some UDP ports and I wrote some lines of rust to do it. There you go: https://github.com/matthid/UdpPortForwarder Works for my use-case but be careful with production workloads.

it does not worked for me, sad to find out is by design 😦

The new experimental networking mode “mirrored” seems to be a possible solution, cf. #4150 (so far only available to Windows Insiders)