Feb 052012
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
VN:F [1.9.22_1171]
Install DNSmasq locally on Mac OS X via Homebrew, 8.5 out of 10 based on 2 ratings Related Posts:
- Determining Local IPv4 and IPv6 Addresses On Mac OS X Via The Command Line
- Updating DNS Entries (with nsupdate or alternative implementations) – Run Your Own DDNS
- A Collection Of Reliable Public DNS Servers
- TP-Link TL-SG3210, 8-Port, Managed Switch
- Generate Bind Reverse Zone File Using A Simple Python Script
I’m curious if you know how to modify this setup to work with upstream servers provided by DHCP. Since you’re setting
resolv-file=/etc/resolv.dnsmasq.confdnsmasq is no longer paying attention to resolv.conf which is where os x lists the current dns servers. I can set dnsmasq to use resolv.conf but when i tell my machine to resolve DNS addresses locally I create a loop – my mac saves 127.0.0.1 to resolv.conf and the dhcp provided dns servers have disappeared from the file.Hi matt, I would do it as follows:
/etc/resolv.dnsmasq.conf).So to set up a script to be run on network changes, I was looking for information on how to do it on google:
/Library/Preferences/SystemConfigurationas shown in http://tech.inhelsinki.nl/locationchanger//etc/dhclient-enter-hooks(NetBSD) doesn’t exist for Mac OS X./System/Library/SystemConfiguration/Kicker.bundle/Contents/Resources/Kicker.xmlhas been an option. It is not anymore.If you need more help, please let me know ;-)
update: I found a regex to parse the ipconfig command ( see https://gist.github.com/1825733 ):
“You also have to uncomment the line that says listen-address=127.0.0.1″ Could you please tell me where I could find that line, to uncomment ? Sorry I’m quite new to OS X so please forgive my ignorance
Hi Jaison! The line
listen-address=127.0.0.1can be found in the file /usr/local/etc/dnsmasq.conf. ;-)[...] http://blog.philippklaus.de/2012/02/install-dnsmasq-locally-on-mac-os-x-via-homebrew/ [...]
[...] machine.One thing that I learned from troubleshooting (in addition to .htaccess behavior) was about DNSMasq. It allows you to create wildcard entries like .dev, which saves a lot of effort editing the [...]