Philipp's Computing Blog

Success is about speed and efficiency

Install DNSmasq locally on Mac OS X via Homebrew

This post describes hot to use dnsmasq as a local DNS server for faster caching and to resolve domain names in your private address space.

Installing dnsmasq

Installing dnsmasq is easy when you have Homebrew installed on your Mac:

brew update && brew install dnsmasq

And follow Homebrew's hints on how to activate dnsmasq:

# copy example configuration file:
cp /usr/local/Cellar/dnsmasq/2.57/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
# To load dnsmasq automatically on startup:
sudo cp /usr/local/Cellar/dnsmasq/2.57/uk.org.thekelleys.dnsmasq.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/uk.org.thekelleys.dnsmasq.plist

Configuring dnsmasq

OK, let's edit the dnsmasq configuration file /usr/local/etc/dnsmasq.conf now.

#address=/www.thekelleys.org.uk/fe80::20d:60ff:fe36:f83
# Change this line if you want dns to get its upstream servers from somewhere other that `/etc/resolv.conf`:
resolv-file=/etc/resolv.dnsmasq.conf

You also have to uncomment the line that says listen-address=127.0.0.1 .

Then save the following as /etc/resolv.dnsmasq.conf:

# Philipp's custom nameserver selection
# OpenDNS IPv6:
nameserver 2620:0:ccd::2
# Google:
nameserver 8.8.8.8
# OpenDNS IPv6:
nameserver 2620:0:ccc::2
# OpenDNS:
nameserver 208.67.222.222

(Re)Starting dnsmasq (The sudo launchctl load -w [...] command must have been run beforehand):

sudo launchctl stop uk.org.thekelleys.dnsmasq && sudo launchctl start uk.org.thekelleys.dnsmasq

Tell OS X to use dnsmasq

Now, edit /etc/resolv.conf to have ONLY the following line in it:

nameserver 127.0.0.1

Set the DNS settings in the network settings' system preferences pane to 127.0.0.1 and ::1 to change this permanently.

Resources