Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mandeepsmagh/f1d062fc59e4e6115385c2609b5f0448 to your computer and use it in GitHub Desktop.

Select an option

Save mandeepsmagh/f1d062fc59e4e6115385c2609b5f0448 to your computer and use it in GitHub Desktop.
Assuming you have followed all the steps to install / setup WSL2 -> https://docs.microsoft.com/en-us/windows/wsl/install-win10
**Tested on Ubuntu 20.04**
Step 1 - Find out default gateway and DNS servers
- Navigate to `Control Panel\Network and Internet\Network Connections`
- Right click on relevant connection type WiFi or Ethernet and select `Status`
- Status screen will be displayed, click on `Details` button
- Network Connection details screen will be displayed
- Note down `IPv4 default gateway` and `IPv4 DNS Servers` if available
**OR**
- Run following command from powershell or cmd
`ipconfig /all`
- Note down `Default Gateway` and `DNS Servers` for relevant connection type WiFi or Ethernet
Step 2 - Create `wsl.conf` file
- Login to WSL2 and create sudo vi `/etc/wsl.conf` with following content
``
[network]
generateResolvConf = false
``
- Save file.
Step 3 - Delete current `resolv.conf` file
`sudo rm /etc/resolv.conf`
Step 4 - Create new custom `resolv.conf` file
- Use below command to create new file
`sudo vi /etc/resolv.conf`
- enter default gateway and any `IPv4 DNS servers` like below example
``
nameserver 192.168.1.254
nameserver 192.165.1.251
``
- Save file
Step 5 - Restart WSL2
- Open powershell and run following command
`wsl --shutdown`
Step 6 - Test internet connection in WSL2
- ping google.com, it should work now.
@Elihaza
Copy link
Copy Markdown

Elihaza commented Aug 10, 2022

Works for me after rebooting. Also had a pending windows update that's been made on the same reboot. Dunno if it has anything to do. Thanks for the solution anyway !

@jordkris
Copy link
Copy Markdown

jordkris commented Nov 1, 2022

This works:

  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.

Thanks, you're life saver ๐Ÿ‘

@samuelguesnier
Copy link
Copy Markdown

  1. wsl-vpnkit.tar.gz

thanks

@costyn
Copy link
Copy Markdown

costyn commented Jul 26, 2023

Just a note, the original instructions say to remove the original file resolv.conf, but it's not a file, it's a symbolic link. And yes, it's crucial to remove it, otherwise just editing the original will make the symbolic link invalid after wsl restart.

@Aegon95
Copy link
Copy Markdown

Aegon95 commented Jan 15, 2024

This works:

  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.

Thanks, this works for me

@lostation
Copy link
Copy Markdown

This works:

  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.

Woooow yes it works ! THANNNNNNNKS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment