Created
September 7, 2020 10:10
-
-
Save jimhansson/37c36274adbdeacfc45bb32604e66bef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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