Mac – How to use the localhost DNS server when offline, on Snow Leopard

dnsmacnetworking

I've followed these instructions for setting up a local DNS server on my mac, and using it to server wildcard subdomains on localhost. It's a really nice thing:

http://mikeferrier.ca/2011/04/04/setting-up-wildcard-dns-on-localhost-domains-on-osx/

One weakness, though: I'm sometimes trying to work offline, and the local BIND instance is only consulted when you have a live connection with 127.0.0.1 in the DNS server list.

Is there a way to achieve this effect offline?

Best Answer

You need to set your resolver configuration to use 127.0.0.1 for that local domain:

sudo mkdir /etc/resolver
sudo vim /etc/resolver/local

Add the following lines to the /etc/resolver/local configuration:

nameserver 127.0.0.1
search_order 1

The name of the configuration file "local" is the name of your search domain. (Mine happens to be "dev"; if you followed that tutorial, yours would be "local".)

You can then go into your System Preferences / Network configuration and remove the custom DNS server you had set there for 127.0.0.1. The above resolver configuration means your localhost DNS will only be consulted for "local" domains.

More details in this helpful serverfault answer.

Related Question