Per Domain DNS Servers in MacOS

MacOS has a nice facility as part of its DNS resolver that allows you to have a per-domain set of DNS servers. This is especially useful when using VPN services where you still need to use your local resolvers as well as the remote resolvers. Unfortunately, there is nowhere in the GUI to do this, nor any obvious indicator that it is even there.

To use it, you will need to be root for the operations (i.e. run sudo -i to get a root shell).

mkdir /etc/resolver 

This directory does not exist by default. Once you have created it, you just add files into this directory in the same form as the classic /etc/resolv.conf, and would be named as the domain you want to route the DNS requests for. So if you wanted to point requests for hosts in technomancer.com, you would create the file /etc/resolver/technomancer.com and in it you would put:

nameserver 192.168.1.1 192.168.1.2 

This will tell the MacOS resolver that all requests for hosts in the domain technomancer.com will point to DNS servers 192.168.1.1 and 192.168.1.2 rather than the default DNS servers given by DHCP or manually set in the GUI.

If you need to stop the DNS routing, then just remove the file(s) you created in /etc/resolver.

Leave a Comment