Skip to content

Instantly share code, notes, and snippets.

@shrwnsan
Created May 14, 2013 08:56
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 shrwnsan/5574618 to your computer and use it in GitHub Desktop.
Save shrwnsan/5574618 to your computer and use it in GitHub Desktop.
For efficiently using dnsmasq. Based from http://wizardmode.com/2012/06/apache-php-mysql-dev-on-os-x-lion-with-a-minimum-of-pain/ /Library/LaunchDaemons/com.setdns.plist /usr/local/bin/setdns.sh
<?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.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>
# /private/etc/resolver
nameserver 127.0.0.1
domain dev
search_order 1
# /usr/local/etc/dnsmasq.conf
address=/.dev/.sbx/127.0.0.1
listen-address=127.0.0.1
# /private/etc/resolver
nameserver 127.0.0.1
domain sbx
search_order 2
#!/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