Description

This allows to expose the wsl instance to the network, allowing it to get it’s ip from the dhcp server of the router.

Note

Since wsl2 version 2.0.5 it’s easier to expose wsl to the network. see the updated version for more information.

How

  1. Enable the Hyper-V feature on your windows machine.
  2. Reboot.
  3. Open Hyper-V.
  4. Connect to local.
  5. Click Manage virtual switchs button of the right panel.
  6. Create a new virtual switch as External.
  7. Create or edit the .wslconfig located at C:\Users\{YOUR-USER}
  8. Ensure that it contains the following
[wsl2]
networkingMode = "bridged"
vmSwitch = "Bridge" # Here goes the name of the switch you previously created
  1. Run wsl --shutdown.
  2. Open a new wsl terminal.
  3. Everything should work now 😄

Updated Version

Since wsl2 version 2.0.5 it’s easier to expose wsl to the network.

Instead of creating a virtual switch, and setting the networking mode to bridged. The servers running in wsl can be exposed using the mirrored networking mode.

[wsl2]
netwrorkingMode = "mirrored"

The main difference is that the mirrored mode will expose the wsl instance to the network as if it where the host machine. Instead of the dhcp server of the router assigning an ip to the wsl instance, it will use the one already assigned to the host windows machine.

Resources