Restore WSL2 network connectivity when using a VPN
WSL2 is often used by developers on Windows. However, if you are using WSL for the company you are working for, it might be that the VPN solution may affect network connectivity in WSL, resulting in no internet connectivity.
Luckily, there is a solution that solves this issue: wsl-vpnkit. It is a pre-built Linux distribution that doesn't require changing any settings on the host or admin privileges.
Here's how you use it:
- Open a PowerShell prompt and run the following commands:
wsl --import wsl-vpnkit $env:USERPROFILE\wsl-vpnkit wsl-vpnkit.tar.gz --version 2
wsl -d wsl-vpnkit
- Now run the following command anytime you lose network connectivity when connecting to VPN:
wsl.exe -d wsl-vpnkit service wsl-vpnkit start
Alternatively, you can also add this command to your
/.zshrcso that is executed automatically when WSL starts.
Installing Docker in WSL2 with Ubuntu 22.04 will not go without issues if you don't change the iptables configuration.
Sun May 15 2022