WSL tips and tricks v1

This commit is contained in:
theadam 2025-06-07 17:44:33 +02:00
parent 8146838338
commit e646ba3701

35
wsl-tricks.md Normal file
View file

@ -0,0 +1,35 @@
# WSL
WSL is the Windows subsystem for Linux which allows to run Linux VM-like containers on modern Windows OSs.
As it is constantly developed it has annoying bugs and issues that documentation quality is varying, so I try to collect here the useful know-hows to make it usable.
## Change the subnet for WSL NAT
WSL2 by default creates a NAT-ed interface to route the traffic of guest Linux VM over the host.
It is changeable if you would like other network options. However in corporate environments usualy a good idea to keep the official topology. However WSL at setup pick a random /20 subnet from `172.16.0.0/12` to address the virtual machines. If your desired LAN uses this address you will can not access it.
Solution is that change the WSL network subnet into APIPA subnet (169.254.0.0/16) and pick a random subnet.
I picked the `169.254.255.0/24`. To apply this the suggested method is to save this in a `"wsl-change-network.reg"` file.
> If you do it from notepad the double quotations are important to keep the `.reg` extension.
```
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss]
"NatGatewayIpAddress"="169.254.255.1"
"NatNetwork"="169.254.255.0/24"
```
Apply it and enoy, install WSL!
### If WSL already installed
If WSL already installed, do the following
- shut down the WSL from terminal `wsl --shutdown`.
- Run `services.msc` and shut down WSL, or simply open an elevated CMD (run, cmd, CTRL-SHIFT-enter) and type `net stop WSLService`.
- Apply the Registry change.
- Do a cold reboot (desktop, ALT+f4, reboot).