Skip to content

Instantly share code, notes, and snippets.

@emrecavunt
Last active September 18, 2023 10:38
Show Gist options
  • Save emrecavunt/4d474c913dc96012d0d4aeca8efdc175 to your computer and use it in GitHub Desktop.
Save emrecavunt/4d474c913dc96012d0d4aeca8efdc175 to your computer and use it in GitHub Desktop.
WSL2 VPN Network Issue

The problem

Err:1 http://archive.ubuntu.com/ubuntu focal InRelease
  Temporary failure resolving 'archive.ubuntu.com'
  • On wsl2 sudo apt update will fail when connected to Cisco Anyconnect VPN but without vpn it works fine. The problem is when you are connected to anyconnect, wsl fails to resolve the DNS.

The solution

Connect Cisco Anyconnect VPN, then open up powershell as Admin and run the following commands to get the all the available DNS/nameservers. Take note of the DNS/namservers will need later.

Get-DnsClientServerAddress -AddressFamily IPv4 | Select-Object -ExpandProperty ServerAddresses

Then on the same powershell run the following. This will get the search domain that will need later on with the nameservers above.

Get-DnsClientGlobalSetting | Select-Object -ExpandProperty SuffixSearchList
Open up wsl, and run the following commands.

On WSL (Ubuntu or any linux distro)

sudo unlink /etc/resolv.conf # this will unlink the default wsl2 resolv.conf

# This config will prevent wsl2 from overwritting the resolve.conf file everytime
# you start wsl2
cat <<EOF | sudo tee -a /etc/wsl.conf
[network]
generateResolvConf = false
EOF

cat <<EOF | sudo tee -a /etc/resolv.conf
nameserver 10.50... # The company DNS/nameserver from the command in step 1
nameserver 10.50... # The company DNS/nameserver from the 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 step 2
EOF

As Administator in Windows Powershell

Change Cisco Anyconnect metric from default 1 to 6000 inside powershell

Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000

Restart wsl2 on the same elevated powershell, then you can open up wsl2 and it should connect to the internet.

Restart-Service LxssManager
@emrecavunt
Copy link
Author

There is memory leak issue with docker engine at WSL2 see more: microsoft/WSL#8725

wsl2 memory freeze up sometimes while multiple (3) docker container is running, By running below fixes the issue.

🤕

wsl --shutdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment