Repository navigation
[Tip / Root Cause] WSL2 Mirrored Mode: ICMP ping & DNS work, but all outbound TCP times out (0 packets in PktMon) — caused by sysctl overriding ip_local_port_range #42327
Unanswered
JWD (Jwd-gity)
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Symptoms
Sharing a hard-won root cause for anyone stuck in WSL2 Mirrored Mode (
networkingMode=mirrored) with this exact pattern:0x8007054ffallback):ip -brief addr).10.255.255.254:53resolves hostnames immediately).pingworks to both gateway and public IPv4 addresses (e.g.223.5.5.5in 6 ms, 0% loss).curl -4 https://...->curl: (28) Connection timed out,git,apt, etc.)./proc/net/devinside Linux shows TX packets incrementing on the mirroredethXinterface, yet Windowspktmon start --capture --comp allcaptures ZERO (0) outbound TCP packets on the Windows host!Environment verified on: Windows 11 Pro 25H2 (Build
26200.8457), WSL3.0.5.0, Ubuntu.Root Cause
In WSL2 Mirrored Mode, Linux shares the host IP address. To avoid port collisions between Windows and Linux, Windows
FSE Switch/HNSdynamically allocates a strict 4,096-port ephemeral range to WSL on every cold boot (for example43255-47350). WSL writes that range into:nftablestable ip nat -> chain WSLPOSTROUTING(masquerade to :MIN-MAX)/proc/sys/net/ipv4/ip_local_port_rangeIn my distro, an older tuning file
/etc/sysctl.d/99-wsl-network-hardening.confcontained:net.ipv4.ip_local_port_range = 10000 65535When systemd booted Ubuntu,
sysctloverwrote/proc/sys/net/ipv4/ip_local_port_rangeback to10000 65535. Because >92% of Linux's ephemeral source ports now fell outside the 4,096-port range authorized byFSE Switch, almost every outbound TCP/UDP packet was silently dropped at the FSE vNIC boundary before ever hitting the Windows TCP/IP stack (PktMon).That also explains all the symptoms:
pingwork? ICMP has no source port, so FSE port-range enforcement did not drop it.dnsTunneling=trueuses the virtualization tunnel (10.255.255.254).10-Second Check
Run inside your WSL distro as root (
sudoorwsl -u root):If
/proc/sys/net/ipv4/ip_local_port_rangedoes not matchmasquerade to :MIN-MAXinWSLPOSTROUTING(e.g. kernel shows10000 65535or32768 60999), you hit this exact bug.Fix
net.ipv4.ip_local_port_rangefrom/etc/sysctl.d/*.confor/etc/sysctl.conf(do not hardcode the current boot's range, because FSE allocates a fresh 4,096-port window on every WSL cold boot).wsl --shutdown/proc/sys/net/ipv4/ip_local_port_rangenow matchesWSLPOSTROUTINGand TCP works.Bonus Tips (Checked Along the Way)
ufwinside WSL ifiptables-savewarnsTable 'filter' contains incompatible base-chainsalongside WSL'sWSLOUTPUTnftableschain (sudo ufw disable)..wslconfigsection placement:dnsTunneling,firewall, andautoProxybelong under[wsl2], whilehostAddressLoopback=truecurrently still belongs under[experimental](placinghostAddressLoopback=trueunder[wsl2]leavesip route show table 128empty).wsl --shutdownonce FSE port range alignment is intact.Diagnostic Script & Templates
I packaged a read-only check script (
check-wsl-mirrored.sh), full postmortem notes, and safe.wslconfig/sysctl.dtemplates here for easy reuse:https://github.com/Jwd-gity/wsl2-mirrored-network-fix
中文简明摘要
如果你在 WSL2 镜像模式(
networkingMode=mirrored) 遇到:NAT 模式完全正常;镜像模式下 DNS 解析与ping网关/公网(如223.5.5.5)均正常,但所有出站 TCP(curl/git/apt)全部超时,且 WindowsPktMon抓不到任何出站 TCP 包——重点排查 Ubuntu 的/etc/sysctl.d/*.conf是否配置了net.ipv4.ip_local_port_range。Windows
FSE Switch每次冷启动只为镜像模式动态分配 4096 个端口(可在nft list chain ip nat WSLPOSTROUTING看到),一旦sysctl将其覆盖为10000 65535等大范围,92%+ 的出站 TCP 会因源端口越界被虚拟交换机静默丢弃。注释掉该sysctl项后执行wsl --shutdown即可彻底恢复(包括与 Mihomo/FlClash TUN 模式的免重启热切换)。详情与一键自检脚本见上方 GitHub 仓库。All reactions