9

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.

11

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.

0

Is there a specific reason for using dnsmasq?

You could simply add entries to your /private/etc/hosts file leaving DNS pointed to whichever ISP you happen to be connected to. Here's how to do that using Terminal:

sudo nano /private/etc/hosts Enter you password when prompted.

Add any additions at the end of the hosts file (a single entry per line), for example:

127.0.0.1 local.dev

Control + O and then enter to save the file within nano. Control + X to exit nano.

You'll than need to flush the local DNS cache using: dscacheutil -flushcache

  • 2
    Use hosts file can be a simple solution, but I need to setup wildcard domains such as *.dev to point to localhost. – Daiwei Mar 27 '13 at 22:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .