Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add local dnsmasq to host resolver order
<?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>
#!/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