In my case if not on VPN, the internet on my WSL works. When I connect to VPN it suddenly stops working.
There is a relevant discussion (still open the day I'm posting) on internet loss on WSL while on VPN here.
This solution presented before for this question works but requires reboot:
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
The other solution presented before:
sudo nano /etc/resolv.conf
with the change of the nameserver to 8.8.8.8 or 1.1.1.1 or any other random address it does not work for me while on VPN.
What solved it though is a hybrid of this second solution and the discussion presented above:
Step 1:
While on VPN in Powershell:
ipconfig /all
Search for your adapter that is linked to your VPN connection. Usually you can find in the description something like
"CISCO Anyconnect ..."
Search in that block the addresses of your DNS servers (for me first DNS server didn't work so I took the second)
Step 2:
Taken from that same discussion here, in PowerShell:
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000
Step 3:
While on VPN on my WSL :
$ sudo echo "nameserver <the DNS server address from point 1>" > /etc/resolv.conf
The drawback of this solution (as for the previous ones) is that you need to do it at every new launch of your WSL.
To make it a bit easier one can create a short .sh script to automate it.
On your WSL:
$touch restore_internet_connection.sh
$nano restore_internet_connection.sh
place the below text inside:
echo "nameserver <the output from point 1>" > /etc/resolv.conf
Next time you have the issue you just repeat step 2 and:
$sudo restore_internet_connection.sh
sudo nano /etc/resolv.conf
, put#
before existing entries, addnameserver 8.8.8.8
on its own line, save (Ctrl+X; Y; Enter),ping google.com
to make sure it worked, then to make sure it doesn't get overwritten:sudo nano /etc/wsl.conf
, add[network]
on its own line, thengenerateResolvConf = false
on the next line, save, and you're done.