WSL Mirrored Networking Mode (Host Mode)
Mirrored networking mode is an advanced WSL 2 networking architecture that mirrors Windows network interfaces into Linux, providing enhanced compatibility and features compared to the default NAT (Network Address Translation) mode.
Overview
System Requirements:
- Windows 11 22H2 or higher
- WSL 2 (Windows Build 19041+)
- WSL version 2.0.0 or higher
Key Benefits:
- IPv6 Support: Full IPv6 protocol support in WSL distributions
- VPN Compatibility: Improved connectivity when using VPN solutions
- Multicast Support: Enables mDNS and other multicast protocols
- Direct LAN Access: WSL instances can be accessed directly from local area network
- Reduced NAT Overhead: Eliminates double NAT scenarios in complex network environments
Architecture Comparison
Default NAT Mode
In NAT mode, WSL creates a virtual network adapter with a separate subnet (typically 172.x.x.x). Windows acts as a NAT gateway, translating network addresses between WSL and the external network. This introduces:
- Port forwarding requirements for inbound connections
- IPv4-only communication
- VPN compatibility issues
- Additional network latency
Mirrored Mode
Mirrored mode creates a bridge between Windows and WSL network interfaces, allowing:
- Direct network interface access from Linux
- Automatic synchronization of network configuration
- Transparent routing between Windows and WSL
- Support for advanced networking protocols
Config file location
Path to Configuration file
1C:\Users\<user>\.wslconfigRun in terminal
1.wslconfigEnable host mode networking
1[wsl2]2networkingMode=mirroredAdvanced Configuration Options
Complete .wslconfig Example
1[wsl2]2# Enable mirrored networking mode3networkingMode=mirrored4
5# DNS tunneling for improved DNS resolution6dnsTunneling=true7
8# Firewall integration with Windows Defender9firewall=true10
11# Automatic memory reclaim (requires Windows 11)12autoMemoryReclaim=gradual13
14# Memory allocation (in GB)15memory=8GB16
17# Processor count18processors=419
20# Swap size21swap=8GB22
23# Virtual hard disk limit24vmIdleTimeout=60000Automatic Network Configuration
WSL automatically configures the following Linux kernel network settings in mirrored mode:
| Setting | Value | Purpose |
|---|---|---|
net.ipv4.accept_local | 1 (Enabled) | Accept locally-destined packets |
net.ipv4.route_localnet | 1 (Enabled) | Enable routing of local addresses |
net.ipv4.rp_filter | 0 (Disabled) | Disable reverse path filtering |
net.ipv6.accept_ra | 0 (Disabled) | Disable router advertisements |
net.ipv6.autoconf | 0 (Disabled) | Disable IPv6 autoconfiguration |
net.ipv4.arp_filter | 1 (Enabled) | Enable ARP filtering per interface |
Warning: Manual modification of these settings while using mirrored mode is not supported and may cause network instability.
Port Exclusion Configuration
Some Windows services use specific ports that should not be forwarded to WSL. You can exclude ports using the ignoredPorts setting:
1[wsl2]2networkingMode=mirrored3
4# Exclude ports from being forwarded to WSL5ignoredPorts=135,445,1900,2869,3702,5004,5357,5358Default Excluded Ports:
- 68 (UDP): DHCP client
- 135 (TCP): DCE endpoint resolution
- 1900 (TCP): UPnP (Universal Plug and Play)
- 2869 (TCP): SSDP events
- 3702 (TCP): WS-Discovery
- 5004 (TCP): RTP (Real-time Transport Protocol)
- 5357-5358 (TCP): WSD (Web Services for Devices)
Applying Configuration Changes
After modifying .wslconfig, restart WSL to apply changes:
1# Shutdown WSL completely2wsl --shutdown3
4# Verify WSL is stopped5wsl --list --verbose6
7# Start your distribution8wsl -d UbuntuVerification and Troubleshooting
Check WSL Version
1# Check WSL version and build2wsl --version3
4# Expected output:5# WSL version: 2.0.0.0 or higher6# Kernel version: 5.15.x or higherVerify Network Interfaces
1# List network interfaces in WSL2ip addr show3
4# Check routing table5ip route show6
7# Test IPv6 connectivity8ping6 google.comView Network Configuration
1# Display current WSL network settings2cat /etc/resolv.conf3
4# Check DNS resolution5nslookup microsoft.com6
7# Test multicast DNS (if mDNS is configured)8avahi-browse -a -tCommon Issues and Solutions
Issue: Docker containers fail with published ports
1# Workaround 1: Use host networking2docker run --network host <image>3
4# Workaround 2: Add ports to ignoredPorts in .wslconfig5[wsl2]6networkingMode=mirrored7ignoredPorts=8080,3000,5000Issue: VPN incompatibility Some VPNs are known to be incompatible with mirrored mode:
- Bitdefender VPN
- OpenVPN (specific versions)
- McAfee Safe Connect
Consider using NAT mode with these VPNs or consult vendor documentation for WSL compatibility.
Multicast DNS (mDNS) Configuration
Mirrored mode supports mDNS for resolving .local domains. Configure Avahi for mDNS support:
1# Install Avahi daemon (Ubuntu/Debian)2sudo apt update3sudo apt install avahi-daemon libnss-mdns4
5# Enable and start the service6sudo systemctl enable avahi-daemon7sudo systemctl start avahi-daemon8
9# Verify mDNS resolution10ping mydevice.localConfigure NSSwitch for mDNS
1# Edit /etc/nsswitch.conf2sudo nano /etc/nsswitch.conf3
4# Ensure this line includes 'mdns4_minimal' or 'mdns':5# hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4Performance Considerations
Network Latency
Mirrored mode typically reduces network latency by 10-20% compared to NAT mode due to elimination of address translation overhead.
Memory Usage
Mirrored networking may use slightly more memory (~50-100MB) for maintaining network interface mirrors.
CPU Impact
Minimal CPU overhead; network operations are handled directly by the kernel without additional translation layers.
Security Implications
Firewall Integration: When firewall=true is enabled in .wslconfig, WSL integrates with Windows Defender Firewall, applying Windows firewall rules to WSL traffic.
Direct Network Exposure: Unlike NAT mode, mirrored mode exposes WSL services directly to the local network. Ensure proper firewall rules and service hardening.
Recommended Security Practices:
1# Check open ports in WSL2sudo ss -tulpn3
4# Configure UFW (Uncomplicated Firewall)5sudo apt install ufw6sudo ufw enable7sudo ufw allow 22/tcp # SSH8sudo ufw allow 80/tcp # HTTP9sudo ufw allow 443/tcp # HTTPS10sudo ufw status verboseBest Practices
- Always test after enabling: Verify network connectivity and application functionality
- Document port requirements: Keep track of ports used by your services
- Monitor system logs: Check for network-related errors
- Use DNS tunneling: Enable
dnsTunneling=truefor improved DNS resolution - Regular updates: Keep WSL updated with
wsl --update