Skip to content

Instantly share code, notes, and snippets.

@elulcao
Last active October 15, 2022 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elulcao/c8e50e7dd10ac3d29ddc82ff3ffe3cbd to your computer and use it in GitHub Desktop.
Save elulcao/c8e50e7dd10ac3d29ddc82ff3ffe3cbd to your computer and use it in GitHub Desktop.
VPN client over-riding DNS on macOS
#!/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