How to Configure Mirrored Networking in WSL 2 on Windows 11 Using PowerShell

Windows Subsystem for Linux (WSL 2) traditionally utilizes Network Address Translation (NAT) to route traffic between the virtualized Linux kernel and the Windows host. While functional, NAT introduces routing complexities: Linux containers cannot be easily reached from local LAN devices, VPN clients frequently disconnect WSL connections, and binding services to localhost across environments often requires port forwarding rules. Windows 11 introduces Mirrored Networking mode, seamlessly mirroring host network interfaces directly into Linux.

Understanding Mirrored Networking Benefits

Configuring mirrored mode in WSL 2 delivers several enterprise networking capabilities:

  • Bi-Directional Localhost Binding: Web servers or microservices running in Linux bind directly to 127.0.0.1 on the Windows host, eliminating cross-environment port forwarding.
  • Full IPv6 Connectivity: WSL 2 inherits the host’s native IPv6 addresses, enabling dual-stack development and testing.
  • VPN Compatibility: Enterprise VPN software (such as Cisco AnyConnect or GlobalProtect) routes traffic seamlessly through Linux without breaking DNS resolution.
  • Direct LAN Access: Other workstations and devices on your physical local area network can connect directly to services hosted inside WSL using the Windows PC’s local IP address.

Configuring Mirrored Networking in .wslconfig via PowerShell

To enable mirrored networking globally across all WSL 2 distributions using PowerShell:

# Define global WSL configuration path
$wslConfigPath = "$HOME\.wslconfig"

# Construct modern experimental configuration payload
$configContent = @"
[wsl2]
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true
"@

# Write configuration file with UTF8 encoding
Set-Content -Path $wslConfigPath -Value $configContent -Encoding UTF8
Write-Host "Mirrored networking configured in $wslConfigPath" -ForegroundColor Green

This automated script enables mirrored mode alongside dnsTunneling (which resolves VPN DNS conflicts) and firewall (which applies Windows Defender Firewall rules directly to Linux traffic).

Restarting WSL to Enforce Mirrored Interfaces

To initialize the virtual machine with mirrored networking enabled:

  1. Open an elevated PowerShell prompt and execute:
    wsl --shutdown
  2. Relaunch your Linux distribution:
    wsl
  3. Inspect network interfaces inside Linux:
    ip addr show
  4. Notice that Linux now lists the exact same network adapters (such as eth0 or Wi-Fi) and IP addresses assigned to your physical Windows host machine.

Deploying mirrored networking transforms WSL 2 into a seamless, first-class citizen on enterprise corporate networks.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.