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
version2.0.5
it’s easier to exposewsl
to the network. see the updated version for more information.
How
- Enable the
Hyper-V
feature on your windows machine. - Reboot.
- Open
Hyper-V
. - Connect to local.
- Click
Manage virtual switchs
button of the right panel. - Create a new virtual switch as
External
. - Create or edit the
.wslconfig
located atC:\Users\{YOUR-USER}
- Ensure that it contains the following
[wsl2]
networkingMode = "bridged"
vmSwitch = "Bridge" # Here goes the name of the switch you previously created
- Run
wsl --shutdown
. - Open a new
wsl
terminal. - 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.