DEV Community

Cover image for Expose WSL2 to local network permanently.
hαršh vαᎥrαgᎥ 🐼
hαršh vαᎥrαgᎥ 🐼

Posted on

Expose WSL2 to local network permanently.

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
Enter fullscreen mode Exit fullscreen mode

Step 2: Add the mirrored mode setting

Add the following lines to the .wslconfig file and save it:

[wsl2]
networkingMode=mirrored
Enter fullscreen mode Exit fullscreen mode

Step 3: Shut down and restart WSL2

Shut down all WSL2 instances to apply the changes.

wsl --shutdown
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

To disable the firewall entirely (easiest but less secure):

Set-NetFirewallHyperVVMSetting -Name ((Get-NetFirewallHyperVVMCreator).VMCreatorId) -Enabled False
Enter fullscreen mode Exit fullscreen mode

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)