Apple - How to add some additional DNS search domains without ignoring the DHCP ones?

Just put a file in /etc/resolver/ with a name such as "searchappend" with these contents:

search example.com

Just don't name the file "com" or some other valid TLD. This works because of OSX's resolver magic. For more info, read through the documentation on your mac with this command:

man 5 resolver

I have a file there called "consul" that looks like this:

nameserver 127.0.0.1
port 8600
search consul

That magically makes it so .consul is appended to the search path, and any resolving for .consul TLDs uses my local nameserver.


You could use the networksetup command, and add the additional search domains in an array on the comand line: From the man page:

-setsearchdomains networkservice domain1 [domain2] [...]

Use this command to designate the search domain for the specified
<networkservice>. You can list any number of search domains
(replace domain1, domain2, and so on with the name of a local
domain). If you want to clear all search domain entries for the
specified network service, type aemptya in place of the domain

So:

sudo networksetup -setsearchdomains Wi-Fi legacydomain.com secondlegacydomain.com additionaldomain.org evenmoresearchdomain.net

this invocation should have the proper order.

Tags:

Macos

Dns

Network