Skip to content
Advertisement

Windows host can’t receive UDP packets from WSL-2 guest

I’m trying to have a simple UDP echo client/server communicate with each other. The client program (which runs in the host Windows) sends packets to the server (which runs in WSL-2), and the server receives them, but the server’s reply is never reaches the client.

import sys
from socket import *
from select import select

client = sys.argv[1].startswith("c")
host = sys.argv[2] if len(sys.argv) > 2 else "127.0.0.1"
port = 8080
sd = socket(AF_INET, SOCK_DGRAM)

def poll():
    readable, writable, errorset = select([sd], [sd], [sd], 0)
    return sd in readable

if client:
    sd.connect((host, port))
    sd.setblocking(0)
    sd.send(b"Hello!")
    while not poll():
        pass
    data, addr = sd.recvfrom(65535)
    print(f"RECV {addr} => {data}")

else:
    sd.bind((host, port))
    print(f"Listening on {host}:{port}")
    sd.setblocking(0)
    sd.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)

    while True:
        while poll():
            data, addr = sd.recvfrom(65535)
            print(f"RECV {addr} => {data}")
            sd.sendto(data.decode("utf-8").upper().encode("utf-8"), addr)

The output on Windows:

udpecho.py client 172.25.154.133

The output on Linux:

$ python3 udpecho.py server 172.25.154.133
Listening on 172.25.154.133:8080
RECV ('172.25.144.1', 57661) => b'Hello!'

And now I’m stumped. TCP connections work ok so it must only be a UDP thing, but I don’t know what to try next.

Running Windows 10 Home edition and hosting Ubuntu-20.04 in WSL 2.

Advertisement

Answer

This sounds like this Github issue, where UDP packets smaller than 12 bytes don’t make it from WSL2 to the host Windows interface.

If so, then a reported workaround is to turn off transmission checksumming in WSL2 via:

ethtool -K eth0 tx off

It sounds like this may be a Hyper-V networking issue that can be reproduced outside of WSL2, and the Microsoft team says it is under investigation.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement