Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I do web development and I would like to have dnsmasq running and handing my local dns requests. However I work in a lot of different networking scenarios and I need to DHCP updating my networking information multiple times a day.

I already have dnsmasq running and I can have my laptop always use it by setting the DNS name server.

It's not too bad, this way, I can use the location management (in the network preference pane) and just switch location between 'Automatic' and 'Automatic (dnsmasq)' when I need to, however what I really want it something linux has.

In linux I can configure my dhcp client to prepend a name server to whatever I get from dhcp. On ubuntu I do this by editing /etc/dhcp3/dhclient.conf and setting.

prepend domain-name-servers;

Is there an equivalent in OS X (10.8 Mountian Lion). Thanks

share|improve this question
up vote 1 down vote accepted

As you already know, OS X will overwrite any changes you make to /etc/resolv.conf so you can't really specify your own nameserver in there. Luckily, there is a way to add your own resolver entries in a way that will persist whatever network connection you use whilst still using DHCP assigned name servers for most normal lookups.

Create the directory /etc/resolver and create a text file within it that simply has a standard name server directive like nameserver Make sure this text file is named the same as the domain or TLD you wish to use dnsmasq for. In my case, all my development sites end with the .dev TLD so my config file is named /etc/resolver/dev.

And that's it! From now on, when ever you connect to a network using DHCP, your name servers will be automatically assigned and used as normal but any requests for your specified TLD (*.dev in my example) will be routed to dnsmasq.

share|improve this answer
That sounds great but, I can't get it to work. In my case I've been using .loc as a TDL so I setup /etc/resolver/loc. I setup the files how you suggest but when I run dig frankie.loc I do not get an answer but when I run dig @ frankie.loc I do. – Jachin Mar 29 '13 at 20:16
Oh, wait, dig didn't work, but ping did. So it does work, thanks a lot, this is exactly what I needed. – Jachin Mar 29 '13 at 20:26

Check this question: How to add some additional DNS search domains without ignoring the DHCP ones?.

It basically says you should try either adding to /etc/resolv.conf or adding your DNS servers manually in System Preferences, putting on the top. (I couldn't test any of the solutions, don't have a Mac around...)

Beware: If is your first DNS server you may notice a delay in name resolution. That's because any DNS request that can't serve will need some time to be processed before the next DNS server in the list is queried (unless your DNS server is configured to forward requests it can't handle).

share|improve this answer
I'm afraid this does not work (at least not when I switch networks). To make sure I just tested it. I can add nameserver to /etc/resolv.conf but as soon as I switch to another network and get new network information from DHCP it over writes /etc/resolv.conf (removing nameserver – Jachin Nov 26 '12 at 22:28
Have you tried the second solution, that is, adding your DNS servers manually in System Preferences (which will override the DHCP provided ones)? – jaume Nov 27 '12 at 6:29
Yes, again, that "works" but I do not get the benefit of the local network's DNS servers. Both at home and at work there are DNS servers that resolve local IP addresses that I need. What I've been doing is using two "locations", when I need to use my own DSN server I use the network locations with the DNS over ridden. When I need the DNS server(s) on my local network I use a different 'location' that does not. This is workable but annoying. – Jachin Nov 27 '12 at 23:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.