Skip to content

Instantly share code, notes, and snippets.

@piyusht007
Created May 15, 2021 14:28
Show Gist options
  • Save piyusht007/d83167da42c2e12dfb2a3d0d4d2c066b to your computer and use it in GitHub Desktop.
Save piyusht007/d83167da42c2e12dfb2a3d0d4d2c066b to your computer and use it in GitHub Desktop.
WSL VPN Fix
# Add below function to the ~/.bashrc file to make it available globally
vpn_fix () {
# Get the DNS servers from windows and add then to the /etc/resolv.conf
powershell.exe -Command 'Get-DnsClientServerAddress -AddressFamily ipv4 | Select-Object -ExpandProperty ServerAddresses' | awk 'BEGIN { print "# Generated by vpn fix func on", strftime("%c"); print } { print "nameserver", $1 } END { print "search", "nuance.com" }' | tr -d '\r' | tee /etc/resolv.conf
echo "/etc/resolv.conf re-written!!"
}
@piyusht007
Copy link
Author

piyusht007 commented May 15, 2021

Issue Description:
While connecting to VPN the /etc/resolv.conf in WSL distro is upadated with reverse order of DNS IPs, This shell function resets the order and make it identical with the Windows.

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