Last active
October 15, 2022 16:58
-
-
Save elulcao/c8e50e7dd10ac3d29ddc82ff3ffe3cbd to your computer and use it in GitHub Desktop.
VPN client over-riding DNS on macOS
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
#!/usr/bin/env bash | |
# Create fixDNS password in Keychain Access for login item | |
PASS=$( security find-generic-password -l "fixDNS" -a fixDNS -w | tr -d '\n' ) | |
# Execute a command with sudo to get a password prompt, next command will be executed with sudo | |
echo "$PASS" | sudo -S true | |
# Execute the command with sudo withing the sudo session | |
echo "$PASS" | sudo -S scutil << EOF | |
get State:/Network/Service/gpd.pan/DNS | |
d.remove SearchDomains | |
d.remove ServerAddress | |
d.add ServerAddresses * 192.168.1.100 fe80::192:168:1:100 | |
set State:/Network/Service/gpd.pan/DNS | |
exit | |
EOF | |
# Show the DNS entries | |
scutil --dns | grep 'nameserver\[[0-9]*\]' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment