Skip to content

Instantly share code, notes, and snippets.

@SinisterMinister
Last active December 11, 2015 18: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 SinisterMinister/4645297 to your computer and use it in GitHub Desktop.
Save SinisterMinister/4645297 to your computer and use it in GitHub Desktop.
dnsmasq setup for osx
# put in /usr/local/etc/dnsmasq.d/
address=/dev/10.1.1.10
#!/bin/bash
# DnsChanger
#
# Automatically change dnsmasq's forward lookup to the dhcp provided dns server.
# Based off of Onne Gorter's LocationChanger which can be found at
# http://tech.inhelsinki.nl/locationchanger/.
#
# author: Codey Whitt <codey.whitt@gmail.com>
# version: 0.1
# redirect all IO to /dev/null (comment this out if you want to debug)
exec 1>/dev/null 2>/dev/null
# get a little breather before we get data for things to settle down
sleep 5
# Clear the file and set the DNS
echo '# Setting DNS from DHCP' > /usr/local/etc/resolv.dnsmasq.conf
# Get the DNS from the DHCP
DNS=`ipconfig getpacket en1 | grep domain_name_server | egrep -o '\{(.*)\}?' | cut -d '{' -f 2 | cut -d '}' -f 1`
OLD_IFS=$IFS;
IFS=', ' read -a servers <<< "$DNS"
IFS="$OLD_IFS"
for ns in "${servers[@]}"
do
echo "nameserver $ns" >> /usr/local/etc/resolv.dnsmasq.conf
done
echo `date` "DNS set to: $DNS" >> /var/log/dnsupdater.log
# Sleep some more so your system won't think your crashing
sleep 5
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>visualguruz.dnsmasq-osx.dnsupdater</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/dnsupdater.sh</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Library/Preferences/SystemConfiguration</string>
</array>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment