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:


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 in the DNS server list.

Is there a way to achieve this effect offline?

  • is offline. You can always connect to = localhost. The only thing you need is the loopback interface aka localhost aka I'm not an osx buff, and I don't have enough cred here to make a comment... What exactly is meant by "work offline"? A safari mode? – Ярослав Рахматуллин Jun 16 '11 at 12:43
  • I'm working on a site that uses subdomains-- using that trick above, I can fake that on localhost, so I have one.mydomain.local, and two.mydomain.local, etc, all resolving to But it only works when I have an active connection. By offline, I just mean not connected to any network – Ross M Karchner Jun 17 '11 at 2:59
  • just make sure "lo", the loop-back is up. ifconfig lo up or whatever (where whatever is something like ifconfig lo up; route add -net gw netmask -- but you should not have to do this manually) – Ярослав Рахматуллин Jun 17 '11 at 3:11
  • Localhost is fine-- what I want is my locally running instance of BIND to be consulted for domain lookups, even when I'm not online. – Ross M Karchner Jun 17 '11 at 11:08

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

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

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

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 The above resolver configuration means your localhost DNS will only be consulted for "local" domains.

More details in this helpful serverfault answer.


The thread A small bit of hardware hacking == No Wi-Fi suggests using a hardware loopback device ($6.79 on Amazon).

This might be a solution to trick OS X into thinking it has a valid network connection.

This also requires using a static IP address, since there is no DHCP server.


  • I'm buying it now to see if this works. Have you actually tried this, along with the local DNS thing? – Barnabas Kendall Jul 4 '11 at 22:07
  • Hope this works for you. But no, I never had this problem, nor a Mac. Did you try just connecting a network cable to the card and using a static IP? – harrymc Jul 5 '11 at 5:59
  • This is interesting-- but there has to be a software solution, right? – Ross M Karchner Jul 6 '11 at 16:49
  • Hmmmm.... maybe. – harrymc Jul 6 '11 at 17:40

Perhaps I am missing something, but you seem to be overlooking the /etc/hosts file completely. Unix operating systems will reference /etc/hosts before making DNS requests. localhost resolves to because it is specified so in /etc/hosts!


You can edit /etc/hosts with any text editor, but you'll need root privileges.

sudo open -a TextEdit /etc/hosts one.mydomain.local two.mydomain.local example.com subdomain.example.com
  • The idea is to not have to manually tend /etc/hosts-- I want anything.local to resolve to – Ross M Karchner Jul 7 '11 at 14:38
  • /etc/hosts is not very helpful when you're developing sites that use dynamic subdomains, like username.example.com. On my local DNS server I have a zone for *.dev so if I just rename ".com" to ".dev" then it goes to my localhost server. – Andrew Vit Jul 31 '11 at 21:05

I want also my bind9 to work when I'm offline. Unfortunately the /etc/resolver/* solution does not work when all NICs are disconnected.

But I found this excellent answer. The only disadvantage is that is run-time based, e.g. the configuration does not survive restart.

To solve this I introduced simple /Library/LaunchDaemon which manages it during the OS startup.

The shell script:



function register() {
    cat <<EOF | /usr/sbin/scutil
d.add ServerAddresses *
d.add SupplementalMatchDomains * <YOUR-DOMAIN-HERE>
set State:/Network/Service/<YOUR-DOMAIN-HERE>/DNS
    echo "$0[$$]" `date` "scutilret:$scutilret" >> "$LOG"

echo "Starting registering " `date` > "$LOG"

for (( i = 0; i < 10; i++ )); do
    scutil --dns 2>&1 >> "$LOG"
    cnt=`scutil --dns | grep | wc -l`
    if [ "$cnt" -ne 0 ]; then
        echo "DNS management done" >> "$LOG"
    echo "DNS not ready yet" >> "$LOG"
    echo "iteration $i" >> "$LOG"
    /bin/sleep 2

echo "DONE" >> "$LOG"

exit 0

The DNS subsystem is not immediately ready when the script starts so hence the check guarded by 10 tries. And the /Library/LaunchDaemons/YOUR-LABEL-HERE.plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <true />
    <true />
    <false />
        <false />

Works while online or offline on macOS Catalina.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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