Switch WSL2 Between NAT and Mirrored via Regedit
This guide explains how to toggle Windows Subsystem for Linux 2 (WSL2) between NAT and mirrored networking modes using the Windows Registry Editor (Regedit). By modifying the WSL registry configuration, you can enforce system-wide network modes to enable advanced features like IPv6 support and localhost binding in mirrored mode, or restore standard network isolation using default NAT mode.
Prerequisites
- Windows 11 version 22H2 (Build 22621) or higher with the latest WSL update installed.
- Administrative privileges on the Windows machine.
Step 1: Open the Registry Editor
- Press
Win + Ron your keyboard to open the Run dialog box. - Type
regeditand press Enter (or click OK). - Select Yes if prompted by User Account Control (UAC).
Step 2: Navigate to the WSL Registry Key
In the Registry Editor address bar, paste the following path and press Enter:
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WSLIf the
WSLkey does not exist underWindows:- Right-click the Windows folder.
- Select New > Key.
- Name the new key
WSL.
Step 3: Configure the Networking Mode Value
- Right-click on an empty space in the right pane of the
WSLkey. - Select New > String Value
(
REG_SZ). - Name the value
networkingMode. - Double-click the newly created
networkingModeentry to edit its data. - Set the Value data according to your requirement:
- Enter
mirroredto enable Mirrored Networking mode. - Enter
natto revert to default NAT Networking mode.
- Enter
- Click OK to save the changes.
Step 4: Restart WSL to Apply Changes
Registry changes to WSL networking do not take effect until the WSL subsystem is fully restarted.
Open Command Prompt or PowerShell as an Administrator.
Shut down all running WSL instances by executing:
wsl --shutdownRelaunch your preferred Linux distribution.
Step 5: Verify the Active Configuration
To ensure the new network mode is applied, launch your WSL distribution and inspect the network interfaces:
- Mirrored Mode: Run
ip addrin the WSL terminal. You will see the exact same network adapters and IP addresses assigned to your host Windows machine. - NAT Mode: Run
ip addrin the WSL terminal. You will see a virtualizedeth0adapter assigned an internal private IP address (typically in the172.x.x.xrange).