Created
June 14, 2012 18:13
-
-
Save ziz/2931901 to your computer and use it in GitHub Desktop.
Add local dnsmasq to host resolver order
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>com.zizproductions.setdns</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/usr/local/bin/setdns.sh</string> | |
</array> | |
<key>QueueDirectories</key> | |
<array/> | |
<key>UserName</key> | |
<string>root</string> | |
<key>WatchPaths</key> | |
<array> | |
<string>/Library/Preferences/SystemConfiguration</string> | |
</array> | |
</dict> | |
</plist> |
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 | |
# Add the localhost dnsmasq server to the head of the nameserver list, if it | |
# is running | |
# short-circuits | |
if [ ! -f /etc/resolv.conf ]; then exit; fi | |
DNSMASQ_RUNNING=`ps auxw | grep [d]nsmasq` | |
if [ -z "$DNSMASQ_RUNNING" ]; then | |
exit | |
fi | |
NAMESERVERS=$(cat /etc/resolv.conf | grep ^nameserver | cut -d' ' -f2- | xargs echo -n) | |
if echo $NAMESERVERS | /usr/bin/egrep -q '127\.0\.0\.1' ; then | |
exit | |
fi | |
logger -s setdns: adding 127.0.0.1 before existing list of nameservers $NAMESERVERS | |
# Find the device ID for the priamry internet interface | |
PSID=$( (scutil | grep PrimaryService | sed -e 's/.*PrimaryService : //')<< EOF | |
open | |
get State:/Network/Global/IPv4 | |
d.show | |
quit | |
EOF | |
) | |
scutil << EOF | |
open | |
d.init | |
d.add ServerAddresses * 127.0.0.1 $NAMESERVERS | |
set State:/Network/Service/$PSID/DNS | |
quit | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment