Disclaimer:
The steps described here where copied from this web site: https://jamespotz.github.io/blog/how-to-fix-wsl2-and-cisco-vpn
All step should be done in the same terminal window.
In Windows, open a powershell terminal as Administrator
Run the following commands:
Get-DnsClientServerAddress -AddressFamily IPv4 | Select-Object -ExpandProperty ServerAddresses
Get-DnsClientGlobalSetting | Select-Object -ExpandProperty SuffixSearchList
Execute wsl -d <distro>
, then run the following commands:
sudo unlink /etc/resolv.conf # this will unlink the default wsl2 resolv.conf
sudo chattr -i /etc/resolv.conf # this will ensure the file is not in read-only mode
# This config will prevent wsl2 from overwritting the resolve.conf file everytime
# you start wsl2
cat <<EOF | sudo tee -a /etc/wsl.conf
[network]
genearteResolvConf = false
EOF
cat <<EOF | sudo tee -a /etc/resolv.conf
nameserver 10.50... # The company DNS/nameserver from the 1st command in step 1
nameserver 10.50... # The company DNS/nameserver from the 2nd command in step 1
nameserver 8.8.8.8
nameserver 8.8.4.4
search this.searchdomain.com # The search domain that we got from 2nd command
EOF
exit
Back in powershell terminal, run the following commands:
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000
wsl --shutdown
Restart-Service LxssManager
To confirm you've got internet connectivity in WSL, run:
wsl -d <distro>
curl www.duckduckgo.com
If above doesn't work, check you have connection in your Windows. If the error persists, I have sad news for you...
Doesnt work for me, corporate network that uses anyconnect, so frustrating. +12 months no fix for the majority of folks, bar wsl --set-version xxx 1