Skip to content

Instantly share code, notes, and snippets.

@jimhansson
Created September 7, 2020 10:10
Show Gist options
  • Save jimhansson/37c36274adbdeacfc45bb32604e66bef to your computer and use it in GitHub Desktop.
Save jimhansson/37c36274adbdeacfc45bb32604e66bef to your computer and use it in GitHub Desktop.
#!/bin/bash
Fix /etc/resolv.conf for VPN
echo "modifying nameserver for VPN"
vpn() {
STRING="Changing Conf"
echo $STRING
[ -s /run/resolvconf/resolv.conf -a -L /etc/resolv.conf ] && sudo cp --remove-destination /run/resolvconf/resolv.conf /etc/resolv.conf
local sudo="sudo"
if [ -w /etc/resolv.conf ]; then sudo=""; fi
$sudo ed -s /etc/resolv.conf <<'EOF'
H
a
#EOF
.
kx
g/^nameserver /d
.-1r !/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command '$x = Get-NetAdapter | Group-Object -AsHashtable -Property ifIndex; Get-DnsClientServerAddress -AddressFamily ipv4 | where {$x[$_.InterfaceIndex].Status -eq "Up"} | Select-Object -ExpandProperty ServerAddresses | foreach {"nameserver " + $_}
' | sed 's/\r//g'
'xd
wq
EOF
}
vpn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment