How to setup Linux with WSL-VPNkit on WSL2 - Tue, Jan 30, 2024
In this guide we are going to learn how to setup Linux with WSL-VPNkit on WSL2.
Pre-requisites
- Windows 10 build 18917 or higher
- Powershell (with Administrator access)
- Linux sub-system for Windows (in this guide we will use Ubuntu 22.04 distro)
Install WSL on your windows machines
Steps
Simply follow this guide to enable and setup WSL on your windows laptop:
- Disconnect from VPN (if connected)
- Reinstall WSL for Windows (if not already installed), Feature “Subsystem for Windows” should stay active. If you don’t have an admin account you can simply order it via ServiceNow: WSL2 - Windows Subsystem for Linux - Installation
- Open PowerShell as administrator
-
Define Version 2 as default for WSL (PowerShell). Details of this in here
> wsl --set-default-version 2
-
Check and Install the distro you would like to install
> wsl -l -o Nedenfor vises en liste over gyldige distribusjoner som kan installeres. Installer ved hjelp av wsl.exe --install <Distro>. NAME FRIENDLY NAME Ubuntu Ubuntu Debian Debian GNU/Linux kali-linux Kali Linux Rolling Ubuntu-18.04 Ubuntu 18.04 LTS Ubuntu-20.04 Ubuntu 20.04 LTS Ubuntu-22.04 Ubuntu 22.04 LTS OracleLinux_7_9 Oracle Linux 7.9 OracleLinux_8_7 Oracle Linux 8.7 OracleLinux_9_1 Oracle Linux 9.1 openSUSE-Leap-15.5 openSUSE Leap 15.5 SUSE-Linux-Enterprise-Server-15-SP4 SUSE Linux Enterprise Server 15 SP4 SUSE-Linux-Enterprise-15-SP5 SUSE Linux Enterprise 15 SP5 openSUSE-Tumbleweed openSUSE Tumbleweed
-
Install the distro choice
# in this example we will use Ubuntu-22.04 but you can choose any distro you prefer > wsl --install -d <distro_name>
-
Set username and password when the installation completes
Note: Docker will not run on WSL version 1
-
Setup WSL-VPNKIT to get access to internet on your Ubuntu machine
Steps
-
Download the binaries on your PowerShell (on the host) (pick the latest version from here)
> VERSION=v0.4.x > wget https://github.com/sakai135/wsl-vpnkit/releases/download/$VERSION/wsl-vpnkit.tar.gz
-
Import the distribution
> wsl --import wsl-vpnkit wsl-vpnkit wsl-vpnkit.tar.gz
-
Run
wsl-vpnkit
. This will runwsl-vpnkit
in the foreground in Linux (WSL)$ wsl.exe -d wsl-vpnkit --cd /app wsl-vpnkit
-
or to run the
wsl-vpnkit
as the service, which can be tricky due to some bugs*, so make sure you are on 2.0.14 or later:> wsl --update Checking for updates. Updating Windows Subsystem for Linux to version: 2.0.14. The requested operation requires elevation. Checking for updates. Updating Windows Subsystem for Linux to version: 2.0.14.
-
Create the .service file (run it on your distro)
$ wsl.exe -d wsl-vpnkit --cd /app cat /app/wsl-vpnkit.service | sudo tee /etc/systemd/system/wsl-vpnkit.service
-
or simply copy and edit for wsl-vpnkit
$ sudo cp ./wsl-vpnkit.service /etc/systemd/system/ $ sudo nano /etc/systemd/system/wsl-vpnkit.service
-
it should look something like this:
-
-
finally enable the service so that
wsl-vpnkit.service
should start with your distro restart next time.$ sudo systemctl enable wsl-vpnkit
-
start and check the status of the service
$ sudo systemctl start wsl-vpnkit $ systemctl status wsl-vpnkit # this helps to see more than a few lines but the tail of the full service log $ journalctl -u wsl-vpnkit.service -e
-
Test the connectivity on your Linux distro:
$ nslookup google.com Server: 1.1.1.1 Address: 1.1.1.1#53 Non-authoritative answer: Name: google.com Address: 142.250.74.14 Name: google.com Address: 2a00:1450:400f:802::200e
Voila! You are done.
Troubleshooting vpnkit as a service
-
It may become a bit tricky as you will probably would run into an error with this message:
/home/username/folder/wsl-gvproxy.exe is not executable due to WSL interop settings or Windows permissions
-
Troubleshooting the WSL version
> wsl --version WSL version: 2.0.5.0 Kernel version: 5.15.133.1-1 WSLg version: 1.0.59 MSRDC version: 1.2.4485 Direct3D version: 1.608.2-61064218 DXCore version: 10.0.25880.1000-230602-1350.main Windows version: 10.0.19045.3930 > wsl -d Ubuntu nslookup google.com ;; communications error to 172.26.32.1#53: timed out ;; communications error to 172.26.32.1#53: timed out ^C > wsl --update Checking for updates. Updating Windows Subsystem for Linux to version: 2.0.14. The requested operation requires elevation. Checking for updates. Updating Windows Subsystem for Linux to version: 2.0.14. > wsl -d Ubuntu nslookup google.com Server: 172.26.32.1 Address: 172.26.32.1#53 Non-authoritative answer: Name: google.com Address: 142.250.74.110