-
-
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. | |
This is a life saver. Took me the whole night and this fixed it!
Doesn't work
This works:
- Download wsl-vpnkit.tar.gz from GitHub.
- 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 .profile, .bashrc or /.zshrc so that is executed automatically when WSL starts.
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 !
This works:
- Download wsl-vpnkit.tar.gz from GitHub.
- 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 startAlternatively, 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 👍
- wsl-vpnkit.tar.gz
thanks
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.
This works:
- Download wsl-vpnkit.tar.gz from GitHub.
- 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 startAlternatively, 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
Most likely settings are being overwritten after reboot.
microsoft/WSL#5420
Have a look at this troubleshooting guide as well in case it helps.
https://docs.microsoft.com/en-us/windows/wsl/troubleshooting