How do I add custom DNS server and preserving default DNS of ISP in OS X Mountain Lion

I'm using OS X Mountain Lion. I'm using dnsmasq to set up wildcard localhost domain names, such as http://local.dev, to point to localhost. But I have to add 127.0.0.1 in my system preference -> network settings.

After I set up 127.0.0.1 as the DNS server, the ISP's default DNS servers were over wrote by mine. This was preventing me from accessing websites. It's not a big deal when I don't move my computer, I could manually enter the ISP's DNS server. But if I change places, the ISP's DNS changes.

I also tried to use google's DNS server, but it's not working in some instance. How can I reserve (or update) the ISP's DNS server without deleting 127.0.0.1 as a DNS.

Thank you in advance.


Yep. You can do this, /etc/resolver is your friend.

$ man 5 resolver:

domain
Domain name associated with this resolver configuration. This option is normally not required by the Mac OS X DNS search system when the resolver configuration is read from a file in the /etc/resolver directory. In that case the file name is used as the domain name.

Simply put you can place nameserver 127.0.0.1 inside a file you create called /etc/resolver/dev

You'll need to reload/restart. It'll then direct any requests to *.dev to your local nameserver.

Your network connection DNS remains on automatic, so it will cope with any changes in your environment.

Edit: I've just found https://serverfault.com/a/164215/163311 and http://www.echoditto.com/blog/never-touch-your-local-etchosts-file-os-x-again which have a few more details and include dnsmasq setup details.