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.
- Make a new folder called
/etc/resolver/
- Inside that folder, create a new file with the name of the domain you want custom DNS settings for, in this case myhugelab.local
- 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
- Save the file, and run
sudo killall -HUP mDNSResponder
in your terminal of choice to force a DNS refresh - 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
- 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.
Related Posts
- Automating Elgato Key Lights From macOS Touch Bar — Published
- macOS: Aggregate Device for Teams - Fixing Auto-Adjusting Mic Level — Published
- macOS: Hiding Menu Bar Icons With Dozer — Published
- macOS: Split Tunnel L2TP VPN Routing — Published
- macOS Keeps Asking for SSH Passphrase — Published