The standard WSL 2 networking architecture places Linux distributions behind a virtual Network Address Translation (NAT) switch. While NAT provides simple outbound internet access, it creates networking barriers when configuring mDNS service discovery, broadcasting UDP packets, or running server services that need to appear as first-class physical devices on your local network. By creating a Hyper-V External Virtual Switch and binding it to WSL 2 via PowerShell, developers can configure true bridged networking with dedicated LAN IP addresses.
Understanding Bridged Networking vs NAT
Bridging fundamentally alters how the host and guest interact with your local router:
- NAT Mode (Default): Linux receives an internal private IP (e.g.,
172.x.x.x) isolated behind the Windows host. External network devices cannot address WSL directly without complex port forwarding rules. - Bridged Mode (Hyper-V External Switch): The virtual machine connects directly to your physical network switch or Wi-Fi adapter. Your local DHCP router assigns the distribution an independent LAN IP address (e.g.,
192.168.1.150) residing on the exact same subnet as your Windows host. - Full LAN Visibility: Enables bidirectional pinging, raw packet sniffing, zero-conf Bonjour/mDNS discovery, and direct port exposure across all local testing devices.
Prerequisites for Bridged Networking
Bridged networking requires the Hyper-V virtualization platform on Windows 11:
- Ensure you are running Windows 11 Pro, Enterprise, or Education.
- Verify that Hyper-V and Virtual Machine Platform are enabled:
Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All - Ensure your physical network adapter (Ethernet or Wi-Fi) is connected to a router with an active DHCP server.
Creating the Hyper-V External Virtual Switch via PowerShell
Open an elevated administrative PowerShell console to identify your active physical adapter and create the external switch:
# Identify your active physical network adapter (e.g., "Ethernet" or "Wi-Fi")
Get-NetAdapter | Where-Object { $_.Status -eq "Up" } | Select-Object Name, InterfaceDescription, MacAddress
# Create an External Hyper-V Virtual Switch bound to your physical adapter
$adapterName = "Ethernet" # Replace with your active adapter name
New-VMSwitch -Name "WSLBridgeSwitch" -NetAdapterName $adapterName -AllowManagementOS $true
The parameter -AllowManagementOS $true ensures your Windows 11 host retains uninterrupted network connectivity through the shared physical port.
Configuring .wslconfig to Use the Bridged Switch
Bind WSL 2 to the newly created Hyper-V external switch:
- Open the global WSL configuration file in your user profile:
notepad "$env:USERPROFILE\.wslconfig" - Insert or update the
[wsl2]section with the bridge switch configuration:[wsl2] networkingMode=bridged vmSwitch=WSLBridgeSwitch dhcp=true - Save and close the file.
- Shut down all running WSL instances from PowerShell:
wsl --shutdown
Verifying Independent IP Address Assignment Inside WSL 2
Launch your distribution to confirm DHCP lease acquisition:
- Start your distribution:
wsl - Check the interface address:
ip addr show dev eth0 - Confirm that
eth0has acquired an IP address matching your local router’s subnet (e.g.,192.168.1.x). - Test external and LAN connectivity:
# Ping your local gateway ping -c 3 192.168.1.1 # Ping external internet hosts ping -c 3 1.1.1.1
Testing LAN Accessibility from Other Devices
Start a simple HTTP server inside WSL 2 to verify LAN accessibility:
python3 -m http.server 8000
From any other smartphone, tablet, or secondary computer connected to your home or office Wi-Fi, open a browser and navigate to http://<wsl-bridged-ip>:8000. The server responds immediately without requiring any port forwarding rules or firewall translation.