When WSL1 first appeared I was pretty excited, a lot of people claim today that because WSL, Windows is the best platform for developers, personally these days I think any OS from the big three can act as a perfect developing platform since many of us use docker anyway.

But back to WSL1, what I really liked was the WSL1 was Cygwin on steroids a kind of “Linux Wine”, and that meant a lot from the perspective of OS development, because it really was a step in the direction of merging OSes rather than have yet another virtual machine.

I mostly switched to WSL2 because I grew tired of my applications crashing because WSL1 was missing some implementations, and I thought I wasted enough time on workarounds like setting Nginx buffering to off, replacing libc libraries, replace system binaries with custom scripts, replacing apt repos with custom ones, adding custom apt repos, changing network IP version preference, avoid using Unix sockets and so on and on(but even TCP wasn’t fully implemented, constantly you could bumble into TCP_INFO error), so basically WSL1 is not extremely stable.

And let’s be honest WSL1 is an incredible piece of software, but in the last year, it received so little attention from the core devs that many of us including me are starting to think it will likely be abandoned. Is hard not to get this feeling when you see issues on GitHub marked as fixed-in-WSL2. And it likely appears that 90% of the developing effort goes towards WSL2, which helped WSL2 a lot, considering that WSL2 from that start was plagued with poor performance, slow startup, inability to access windows files, and without a network bridge between the localhost of the host and VM, but all these today are gone and the and WSL2 has improved significantly, moreover devs are promising that in the future the speeds which WSL2 will be able to access Windows files will increase, which is actually the main problem that WSL2 has now.

If WSL2 will clear this last hurdle then the argument can be made that WSL1 is no longer needed, but I really hope that will not happen, first of all, because, in my opinion no matter how thin is a VM, a VM is not a subsystem layer it as the name implies another machine, so it’s hard to argue that resolving Linux system calls with Window natively is not a better definition of what a subsystem layer should be.

Another thing many WSL2 users want is a static IP for their VM, which not very easy to do now, I guess static IP would be good for a lot of things, including setting a Port Forward from the host machine to the VM since now that we are talking about a VM that can’t be accessed remote without a port forward, and you may want to access it remotely if you want to set up your web environment with SSL.

Luckily you can do that with some scripts, there are many on GitHub, normal I run only “start linux httpd – mysql.cmd” which runs other two scripts, one to start the services, and one to port forward 8443(SSL which is proxied trough ClouldFlare) so that I expose the VM to remote access.

File: “start linux httpd – mysql.cmd

PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:\Users\andrei0x309\Desktop\service scripts\Port Forward 8443 WSL2.ps1""' -Verb RunAs}"
bash "/mnt/c/Users/andrei0x309/Desktop/service scripts/linux start httpd - mysql.sh"

File: “linux start httpd – mysql.sh

sudo service mariadb start;
sudo service nginx start;
sudo service php7.4-fpm start;
sudo service php8.0-fpm start;

File: “Port Forward 8443 WSL2.ps1

$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';

if( $found ){
  $remoteport = $matches[0];
} else{
  echo "The Script Exited, the ip address of WSL 2 cannot be found";


#All the ports you want to forward separated by coma

#[Static ip]
#You can change the addr to your ip config to listen to a specific address
$ports_a = $ports -join ",";

#Remove Firewall Exception Rules
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";

#adding Exception Rules for inbound and outbound Rules
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";

for( $i = 0; $i -lt $ports.length; $i++ ){
  $port = $ports[$i];
  iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
  iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport";

Read-Host -Prompt "Press Enter to exit"

Depending on your WSL2 distro you might have to change how the IP from the VM is extracted, since ifconfig is not available on all distros.