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:
- Download
wsl-vpnkit.tar.gzfrom GitHub. - Open a PowerShell prompt and run the following commands:
wsl --import wsl-vpnkit $env:USERPROFILE\wsl-vpnkit wsl-vpnkit.tar.gz --version 2wsl -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.profile,.bashrcor/.zshrcso that is executed automatically when WSL starts.