How-To Guides5 min read

How to Configure WSL 2 Mirrored Networking and Resource Limits in .wslconfig

Fix WSL 2 VPN drops, localhost failures, and runaway RAM consumption on Windows 11 by configuring mirrored networking, DNS tunneling, and memory limits in .wslconfig.

To enable WSL 2 mirrored networking and cap VM resource usage on Windows 11 (22H2 or later), create or edit %UserProfile%\\.wslconfig, set networkingMode=mirrored, dnsTunneling=true, autoProxy=true, and memory limits under [wsl2], then run wsl --shutdown and wait for all distributions to stop before relaunching.

Key takeaways

  • Mirrored networking replaces fragile netsh portproxy rules and improves corporate VPN compatibility in WSL 2.
  • Always separate global VM settings in .wslconfig from per-distro settings in /etc/wsl.conf.
  • Use wsl --shutdown to restart the WSL 2 VM cleanly so configuration edits take effect immediately.

Quick facts

  • .wslconfig applies globally across all WSL 2 distributions and lives at %UserProfile%\\.wslconfig on the Windows host.
  • Mirrored mode requires Windows 11 version 22H2 or higher and eliminates the separate NAT IP workaround for localhost and VPN traffic.
  • WSL 2 defaults to 50 percent of host RAM unless capped with memory= in [wsl2].
  • Closing a Linux terminal does not apply .wslconfig edits immediately because WSL waits roughly 8 seconds before stopping the subsystem.

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.

Comparison diagram of WSL 2 NAT mode versus Mirrored Networking mode
Comparison diagram of WSL 2 NAT mode versus Mirrored Networking 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 --version and wsl -l -v). Distributions running as WSL 1 ignore .wslconfig completely.
  • Save work warning: Applying .wslconfig changes requires restarting the WSL 2 virtual machine via wsl --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.

POWERSHELL
wsl --version
wsl --list --verbose

If 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.

POWERSHELL
$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:

INI
# %UserProfile%\.wslconfig
[wsl2]
networkingMode=mirrored
dnsTunneling=true
autoProxy=true
firewall=true
memory=8GB
swap=2GB

[experimental]
autoMemoryReclaim=gradual
ignoredPorts=3000,9000

Adjust 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:

POWERSHELL
wsl --shutdown
wsl --list --running

Expected 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.

POWERSHELL
# 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 8080

I 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.

BASH
free -h
ip addr show

Expected 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

SymptomLikely causeFix
Memory or network edits did not apply after closing terminalReopened distro before the 8-second subsystem idle window finishedRun wsl --shutdown, confirm with wsl --list --running, then relaunch
Linux service fails to bind a port in mirrored modeWindows already owns that port on the shared network stackAdd the port to ignoredPorts= under [experimental] if Linux-only traffic is enough
Windows LAN peers still cannot reach WSL web serverHyper-V firewall blocks inbound connections by defaultAdd a scoped New-NetFirewallHyperVRule for the needed port
IPv6 ::1 localhost test fails between Windows and WSLIPv6 loopback is unsupported in mirrored mode per Microsoft docsUse 127.0.0.1 for local host-to-WSL connections
DNS breaks on corporate VPNdnsTunneling disabled or conflicting manual /etc/resolv.confEnsure dnsTunneling=true in .wslconfig and check /etc/wsl.conf

Sources