You can expose WSL2 to your local network permanently using mirrored
networking mode.
Prerequisite
You must have to remind these conditions in mind before proceed with the guide.
- ✅ You must have atleast
Windows 11 22H2
. - ✅ Administration access of your machine.
- ✅ Absolutly you must have
WSL2
configured.
Recommendation
This is completely optional but you create a restore point because we are goint to turn off firewall
for private or entire (all) networks.
Documentation
Run the Windows PowerShell
as Administrator and follow these steps accordingly.
Step 1: Edit .wslconfig
file using notepad
.
Open or create the .wslconfig
file located in your Windows user profile folder. You can do this by running this command in Windows PowerShell
:
notepad $env:USERPROFILE\.wslconfig
Step 2: Add the mirrored mode setting
Add the following lines to the .wslconfig
file and save it:
[wsl2]
networkingMode=mirrored
Step 3: Shut down and restart WSL2
Shut down all WSL2
instances to apply the changes.
wsl --shutdown
Step 4: Configure the Hyper-V firewall
The final step is to allow inbound connections through the Hyper-V firewall that WSL2 uses. Open Windows PowerShell
as an Administrator
and run one of the following commands:
For private networks (safe):
This turn off firewall
for private networks only.
New-NetFirewallHyperVRule -DisplayName 'WSL Private Inbound Rule' -Profiles Private -Direction Inbound -Action Allow -VMCreatorId ((Get-NetFirewallHyperVVMCreator).VMCreatorId)
To disable the firewall entirely (easiest but less secure):
Set-NetFirewallHyperVVMSetting -Name ((Get-NetFirewallHyperVVMCreator).VMCreatorId) -Enabled False
Congrats, your WSL2
services will be directly accessible from other devices on the LAN using your machine's IP address.
Support
If you have any question about this you can follow and ask me on LinkedIn.
Top comments (0)