Skip to content

Instantly share code, notes, and snippets.

@rabimba
Created January 20, 2023 17:10
Show Gist options
  • Save rabimba/a1497643662a7ceee0d229974e966d16 to your computer and use it in GitHub Desktop.
Save rabimba/a1497643662a7ceee0d229974e966d16 to your computer and use it in GitHub Desktop.
AnyConnect DNS resolution fix for WSL2
#!/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 on", strftime("%c"); print } { print "nameserver", $1 }' | \
tr -d '\r' > /etc/resolv.conf
clear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment