From e646ba3701343203f2472e698dedeb14c2fcedaf Mon Sep 17 00:00:00 2001 From: theadam Date: Sat, 7 Jun 2025 17:44:33 +0200 Subject: [PATCH] WSL tips and tricks v1 --- wsl-tricks.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 wsl-tricks.md diff --git a/wsl-tricks.md b/wsl-tricks.md new file mode 100644 index 0000000..ea3f508 --- /dev/null +++ b/wsl-tricks.md @@ -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). +