macOS: Using Custom DNS Resolvers

by Christian Mohn · Read in about 2 min (272 words)

Some times there is a need to use custom DNS servers for some domains, in my case specifically for access to the new lab environment we are building at work (more on that later, this is one beefy lab!)

One way of doing this, is adding custom DNS servers to /etc/resolv.conf but in macOS you really shouldn’t be editing that file manually, as it often gets overwritten or otherwise edited by VPN clients and such.

Thankfully, there is a better way to create persistent and manageable custom domain specific DNS settings.

  1. Make a new folder called /etc/resolvers/
  2. Inside that folder, create a new file with the name of the domain you want custom DNS settings for, in this case myhugelab.local
  3. Edit that file, and add your custom domain, search path and nameservers. My example file looks like this

    domain myhugelab.local
    search myhugelab.local
    nameserver 10.0.0.53
    nameserver 10.0.0.54
    
  4. Save the file, and run sudo killall -HUP mDNSResponder in your terminal of choice to force a DNS refresh

  5. Verify that the new DNS settings are in place by running scutil --dns and looking at the output for the entries added in step 3.

    resolver #8
    domain   : myhugelab.local
    search domain[0] : myhugelab.local
    nameserver[0] : 10.0.0.53
    nameserver[1] : 10.0.0.54
    
  6. Check that name resolution works!

This way I can redirect host name resolution to the lab DNS servers, without having to do anything but connect to that network first. Doing this with /etc/resolver/domainname files, is a lot cleaner than other methods, requires less work and is much easier to keep track of. I’d call that a win every day! And remember, it’s always DNS.

DNS Haiku

Unless it’s NTP.

About the author

Christian Mohn works as a Chief Technologist SDDC for Proact in Norway.

See his About page for more details, or find him on Twitter.

Sponsors