Mac OS X, 10.12.2, Command Line how to add Search Domains

I do this all the time with the GUI and it does what I am looking for. No Problem.

System Preferences > Network > Select the LAN or Wi-Fi > Advanced > DNS > Search Domains and in that particular box field, I add all the search domains that I want. e.g. office, hq, ad.gwn, etc.

Question, how can I achieve the same process via command line with Terminal?

Thank you so much in advance

Posted on Jan 11, 2017 12:18 PM

Reply
6 replies

Jan 12, 2017 8:21 AM in response to dot.com

Step #1 I run both these command line to get an overview of what I have:

  • networksetup -listallnetworkservices
  • networksetup -listnetworkserviceorder

and this is what I got:

  • List item
  • Apple USB Ethernet Adapter
  • Thinkpad USB LAN
  • Wi-Fi
  • Bluetooth PAN
  • Thunderbolt Bridge
  • (1) Apple USB Ethernet Adapter (Hardware Port: Apple USB Ethernet Adapter, Device: en4)
  • (2) Thinkpad USB LAN (Hardware Port: Thinkpad USB LAN, Device: en5)
  • (3) Wi-Fi (Hardware Port: Wi-Fi, Device: en0)
  • (4) Bluetooth PAN (Hardware Port: Bluetooth PAN, Device: en3)
  • (5) Thunderbolt Bridge (Hardware Port: Thunderbolt Bridge, Device: bridge0)

Step #2 I tried to add my search domains (hq, office, ad.gwn) but I received the following error message: - sudo networksetup -setsearchdomains en4 hq office ad.gwn - en4 is not a recognized network service - Error: The parameters were not valid

I am connected only with Ethernet cable. No WiFi. I tried en4 and en5 same issue.

Jan 11, 2017 4:51 PM in response to fabio168

Think what you need is using the "networksetup" command. For example:


networksetup -getsearchdomains ethernet


would list the current search domains for the ethernet interface. A way to define a couple of new domains named "domain1" and "domain2 for the ethernet interface would be:


networksetup -setsearchdomains ethernet domain1 domain2


Do a "man networksetup" for a list of all the other parameters you can set with "networksetup" command. Use "wi-fi" instead of "ethernet" for domains on the WiFi interface if you need that instead.


Good luck...

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Mac OS X, 10.12.2, Command Line how to add Search Domains

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.