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:

  1. Download wsl-vpnkit.tar.gz from GitHub.
  2. 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
  3. 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, .bashrc or /.zshrc so that is executed automatically when WSL starts.
Show Comments