Why default NAT networking breaks real Windows 11 dev loops
Out of the box, WSL 2 boots inside a lightweight virtual machine behind a Network Address Translation (NAT) switch. That works fine until you connect a corporate VPN on Windows and watch DNS fail inside Ubuntu, try to hit a Windows API server from Linux via 127.0.0.1, or attempt to reach a WSL container from another machine on your local network.
On Windows 11 (22H2 and later, including 24H2, 25H2, and 26H2), Microsoft provides networkingMode=mirrored. Instead of translating packets across a private virtual subnet, Windows mirrors your host network interfaces straight into the WSL 2 VM. Both sides can talk over 127.0.0.1 (IPv4 loopback; Microsoft notes IPv6 ::1 is not supported here), Windows VPN routes carry across more reliably, and IPv6 works natively inside Linux.
I keep mirrored mode paired with explicit memory and swap bounds in .wslconfig on every Windows 11 dev machine. By default, WSL 2 can claim up to half of host physical memory plus 25 percent swap, which gets uncomfortable on a 16 GB laptop running Docker and a browser simultaneously. If you rely on Windows 10, or if you use legacy scripts hardcoded to parse NAT virtual switch subnets, I would skip networkingMode=mirrored and keep default NAT mode.
Diagram: Original vector architecture comparison authored for Tech Oblivion (CC BY 4.0), based on Microsoft Learn WSL networking documentation.
Prerequisites and safety check
Check your Windows build and WSL installation before writing .wslconfig.
- Windows version: Windows 11 version 22H2 or higher (check with
winver). Mirrored networking and Hyper-V firewall options are Windows 11 features. - WSL runtime: Store-distributed WSL 2 (check with
wsl --versionandwsl -l -v). Distributions running as WSL 1 ignore.wslconfigcompletely. - Save work warning: Applying
.wslconfigchanges requires restarting the WSL 2 virtual machine viawsl --shutdown, which immediately terminates all running Linux processes, containers, and background jobs.
Important: Save open buffers inside tmux, Neovim, or Docker containers before running wsl --shutdown. Shutting down the VM drops active Linux sessions immediately without graceful container drains unless you close them first.Step-by-step WSL 2 .wslconfig setup
Step 1: Verify your WSL version and current distribution state
Open PowerShell on the Windows host and check that your distribution runs on version 2 and that you are on an updated WSL release.
wsl --version
wsl --list --verboseIf a distribution still reads VERSION 1 and you intend to use .wslconfig, check Microsoft's migration instructions before converting it, or verify whether your project relies on WSL 1 filesystem behavior.
Step 2: Back up any existing .wslconfig file
Because .wslconfig does not exist by default, check whether one is already present in %UserProfile% and copy it before editing.
$wslCfg = Join-Path $env:USERPROFILE ".wslconfig"
if (Test-Path $wslCfg) { Copy-Item $wslCfg "$wslCfg.bak" -Force }Expected result: If a previous .wslconfig existed, a .wslconfig.bak copy now sits alongside it so you can roll back in one command.
Step 3: Write your global .wslconfig settings
Create or overwrite %UserProfile%\.wslconfig using UTF-8 without BOM or plain ASCII INI syntax. Keep global VM settings in .wslconfig and per-distro settings (like systemd=true) inside /etc/wsl.conf inside Linux.
The configuration below enables mirrored networking, keeps Windows HTTP proxies and DNS tunneling aligned, caps RAM on a 16 GB or 32 GB host reasonably, and enables automatic memory reclamation:
# %UserProfile%\.wslconfig
[wsl2]
networkingMode=mirrored
dnsTunneling=true
autoProxy=true
firewall=true
memory=8GB
swap=2GB
[experimental]
autoMemoryReclaim=gradual
ignoredPorts=3000,9000Adjust memory=8GB to fit your physical RAM (for example, 6GB on a 16 GB laptop or 16GB on a 64 GB workstation). Notice ignoredPorts=3000,9000 under [experimental]: Microsoft documents this option specifically for mirrored mode when you want a Linux-only server to bind a port already held by a Windows service without collision.
Note that Windows 11 also exposes these controls through the WSL Settings graphical app in the Start menu, which writes valid configuration syntax without manual escaping errors.
Step 4: Shut down WSL and avoid the 8-second trap
Microsoft documents an important quirk called the 8-second rule: simply closing your Ubuntu terminal window does not stop the WSL 2 subsystem immediately. WSL waits roughly 8 seconds after all shells close before shutting down the VM, so reopening a tab too fast boots back into the old config.
Force a clean restart from PowerShell instead, and verify zero distributions remain active before reopening Linux:
wsl --shutdown
wsl --list --runningExpected result: wsl --list --running prints There are no running distributions.
Step 5: Allow inbound LAN connections if needed (optional)
With firewall=true (the default on modern WSL 2), Hyper-V firewall filters inbound traffic to WSL. Local 127.0.0.1 loopback connections between Windows and Linux work directly under mirrored mode, whereas accepting traffic from other devices on your LAN requires permitting the WSL Hyper-V creator ID in an elevated PowerShell prompt.
# Allow a specific inbound port only (safer than opening all ports)
New-NetFirewallHyperVRule -Name "WSLWebDev" -DisplayName "WSL Port 8080" -Direction Inbound -VMCreatorId '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' -Protocol TCP -LocalPorts 8080I prefer adding scoped per-port rules like the one above rather than setting -DefaultInboundAction Allow globally across the VM, especially on shared corporate or cafe Wi-Fi.
Step 6: Verify mirrored networking and resource limits inside Linux
Launch your WSL distribution again and run a quick check on both memory allocation and localhost connectivity.
free -h
ip addr showExpected result: free -h reports total memory matching your .wslconfig memory= cap, and ip addr show reflects your Windows host adapter addresses rather than a single isolated 172.x.x.x NAT subnet. If a server runs on Windows port 5000, curl http://127.0.0.1:5000 from WSL reaches it directly without querying /etc/resolv.conf or ip route.
Rollback if a tool breaks under mirrored mode
If a legacy tool or container setup misbehaves under mirrored networking, delete or edit %UserProfile%\.wslconfig (or restore .wslconfig.bak), change networkingMode=nat (or remove the line), and run wsl --shutdown. Note that malformed syntax in .wslconfig causes WSL to silently boot with default settings rather than crashing.
Troubleshooting mirrored mode and .wslconfig
| Symptom | Likely cause | Fix |
|---|---|---|
| Memory or network edits did not apply after closing terminal | Reopened distro before the 8-second subsystem idle window finished | Run wsl --shutdown, confirm with wsl --list --running, then relaunch |
| Linux service fails to bind a port in mirrored mode | Windows already owns that port on the shared network stack | Add the port to ignoredPorts= under [experimental] if Linux-only traffic is enough |
| Windows LAN peers still cannot reach WSL web server | Hyper-V firewall blocks inbound connections by default | Add a scoped New-NetFirewallHyperVRule for the needed port |
IPv6 ::1 localhost test fails between Windows and WSL | IPv6 loopback is unsupported in mirrored mode per Microsoft docs | Use 127.0.0.1 for local host-to-WSL connections |
| DNS breaks on corporate VPN | dnsTunneling disabled or conflicting manual /etc/resolv.conf | Ensure dnsTunneling=true in .wslconfig and check /etc/wsl.conf |
