by commented the disable with #
sudo vi /etc/wsl.conf
#[network]
#generateResolvConf = false
sudo vi vpn-dns.sh
#!/bin/bash
echo "Getting current DNS servers, this takes a couple of seconds"
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command '
$ErrorActionPreference="SilentlyContinue"
Get-NetAdapter -InterfaceDescription "Cisco AnyConnect*" | Get-DnsClientServerAddress | Select -ExpandProperty ServerAddresses
Get-NetAdapter | ?{-not ($_.InterfaceDescription -like "Cisco AnyConnect*") } | Get-DnsClientServerAddress | Select -ExpandProperty ServerAddresses
' | \
awk 'BEGIN { print "# Generated by vpn fix func on", strftime("%c"); print } { print "nameserver", $1 }' | \
tr -d '\r' | sudo tee /etc/resolv.conf
sudo chmod +x vpn-dns.sh
sudo vpn-dns.sh
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 6000
It can be restored:
Get-NetAdapter | Where-Object {$_.InterfaceDescription -Match "Cisco AnyConnect"} | Set-NetIPInterface -InterfaceMetric 1
Sources: https://www.frakkingsweet.com/automatic-dns-configuration-with-wsl-and-anyconnect-client/ https://stackoverflow.com/questions/66444822/wsl-2-dns-is-not-working-with-vpn-connection-on-win-10