Set Search Domains from Terminal

6

Is there a file that I can view/edit from terminal that has a list of the search domains?

I know it's possible to set these up from the DNS tab in the Network preferences, but is there a way to do it over the terminal?

Louis

Posted 2014-04-16T20:44:08.457

Reputation: 18 859

Answers

9

You wouldn't necessarily need to view/edit a specific file. In OSX, Mac allows you to modify or set DNS configs among other things by running the networksetup command. The full path is: /usr/sbin/networksetup

Since it's in /usr/sbin -you should be able run the networksetup command from anywhere within the terminal.

You can run something like this:

networksetup -setsearchdomains Ethernet labs.example.com staging.example.com

Hope this helps.

injector

Posted 2014-04-16T20:44:08.457

Reputation: 888

Custom TLDs were (sometimes) failing for me on Mac. So, I used a search domain to 'default' to a *.dev url (for local development).

If you need to reset/clear out your custom search domains that you set via the above command use this: networksetup -setsearchdomains Ethernet Empty

Also, to programmatically get your active network interface, look at this bash script: http://apple.stackexchange.com/a/223446/111516

– CenterOrbit – 2017-03-10T00:39:47.507