macOS: Using Custom DNS Resolvers

Published 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/resolver/
  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
  1. Save the file, and run sudo killall -HUP mDNSResponder in your terminal of choice to force a DNS refresh
  2. 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
  1. 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.

Unless it’s NTP.

Post last updated on January 2, 2024: Add author

About

vNinja.net is the online hub of Christian Mohn and Stine Elise Larsen.

The site primarily focuses on IT architecture and data center technologies, with a strong emphasis on virtualization and related topics.
While the main content revolves around these areas, you'll also find a range of other subjects covered from time to time, reflecting the interests of authors.

Sponsors