Categories
Linux Windows WSL

Easiest way to bridge WSL (windows subsystem for linux)

Its really hard to use WSL2 like a linux box due to how hard it is to make incoming connections from other machines to your WSL instance.

Well a new an hidden feature in the latest WSL preview fixes that. You will need at least version 0.51.2.0 to implement bridging to the host. Here is how to implement it.

  1. issue the wsl –shutdown command
wsl --shutdown
  1. install a new virtual switch using Hyper-V say wsl-switch
  2. to %userprofile%\.wslconfig add the following (if the file doesn’t exist create it)
[wsl2]
networkingMode=bridged
vmSwitch=wsl-switch

Now when you restart WSL you will have a bridge session. This has also be known to cure some of the weird network issues seen with WSL where network connectivity stops working, no DNS connectivity – without the need for messing with scripts and config files. YMMV