I have WSL Version 2 running on my Windows 10 Laptop. I'm using the WSL distribution Ubuntu-20.04. When I connect to a VPN network domain name resolution doesn't work so I can't access the Internet.
VPN Client in use is "Cisco AnyConnect Secure Mobility Client"
I tried the following steps to resolve this problem.
netsh winsock reset
netsh int ip reset all
netsh winhttp reset proxy
ipconfig /flushdns
reboot
That worked once, I had access to the internet. But as soon as I disconnected the VPN connection and connected again, I had the same problem all over again. I tried to just execute the commands again and rebooted, but now thats not working anymore.
What is a permanent fix for this problem?
This issue may occur if you configure the VPN connection to use the default gateway on the remote network. This setting overrides the default gateway settings that you specify in the Transmission Control Protocol/Internet Protocol (TCP/IP) settings.
Windows Subsystem for Linux (WSL) allows Windows 10 devices to run Linux binary within Windows. WSL2, announced in 2019 now uses a full Linux kernel. Note: using the VPN with WSL is not a supported use but may work with a little help.
There is an issue with DNS Forwarding in WSL2 when using VPN (see github Issue). Plus there is a issue with the Cisco AnyConnect. So here is a workaround for these problems. Should work for Ubuntu and Debian.
Find out nameserver with windows powershell (during VPN Session)
nslookup
You'll get the IPv4 adress of your corporate nameserver Copy this address.
Disable resolv.conf generation in wsl:
sudo nano /etc/wsl.conf
copy this text to the file (to disable resolve.conf generation, when wsl starts up)
[network]
generateResolvConf = false
In wsl Add your corporate nameserver to resolv.conf
sudo nano /etc/resolv.conf
Remove other entries and add your corporate nameserver IP (if you have a secondary nameserver, add it in a separate line)
nameserver X.X.X.X
(where X.X.X.X is your address obtained in step 1)Set your VPN adapter (if you have Cisco AnyConnect) open a admin powershell
Get-NetIPInterface
(in my case: "Cisco AnyConnect"
)Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000
(What is interface metric: Used to determine route, windows use interface with lowest metric)
Restart wsl in powershell: wsl.exe --shutdown
Test it in wsl run: wget google.com
- if this command works, you are done.
In my case I get DNS issues when try to connect to internal stuff via browser (on Windows 10, f.e.: intranet), caused by the high metric value set in step 4 (basically kind of disabling VPN Route). So here is the workaround for the workaround:
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Get-NetIPInterface
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 1
This worked for me.
How Anyconnect v4.9 breaks it: It adds a route for wsl2 with a low metric 2, lower than 5256, which causes vpn becomes the chosen route, and of course that will never work. As seen below. c:> route.exe print Note: “172.17.228.192 255.255.255.240” is the wsl2 destination subnet. 172.17.228.192 255.255.255.240 On-link 172.17.228.193 5256 172.17.228.192 255.255.255.240 10.255.0.1 10.255.0.71 2 This problem is solved when I change the vpn route metric to 5500, higher than 5256, by doing so: Control Panel – network – click the vpn – property – IPv4 – property, advanced – automatic metric: uncheck it and type in 5500.
source: https://riowingwp.wordpress.com/2020/12/13/anyconnect-bug/
There is an issue with VPN integration in WSL running on my Windows 10. You need to redirect WSL to VPN, please follow these steps:
STEP-1: Obtain DNS address from Windows Power Shell
>nslookup
Servidor predeterminado: yyyy.com
Address: x.x.x.x
or
>ipconfig /all
STEP-2 Open Ubuntu-20.04 Version 2 WSL and open /etc/resolv.conf
STEP-3 Modify /etc/resolv.conf . Add the VPN Address in the first position(I deleted the others directions but it is not necessary), save the file, and try to access again. My file looks like:
nameserver X.X.X.X
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With