-
-
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. | |
Worked for me too, seems like such a simple fix, tried so many over the last few months and nothing worked.
Thank you
Unfortunatly, this seems to have stopped working since restarting my laptop :(
I have tried running the same steps a few times, but no luck, I even converted the install back to wsl v1 and then back to v2, but still no luck
Swapping back to wsl v1 and all works fine, other than it being very slow to run stuff :(
Unfortunatly, this seems to have stopped working since restarting my laptop :(
I have tried running the same steps a few times, but no luck, I even converted the install back to wsl v1 and then back to v2, but still no luck
Swapping back to wsl v1 and all works fine, other than it being very slow to run stuff :(
Most likely settings are being overwritten after reboot.
Have a look at this troubleshooting guide as well in case it helps.
https://docs.microsoft.com/en-us/windows/wsl/troubleshooting
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
If you are unable to edit and save /etc/resolv.conf
'lsattr /etc/resolv.conf'
----i--------------- /etc/resolv.conf
Remove the flag by
'sudo chattr -i /etc/resolv.conf'
Should work now