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?

So far this is what I did:

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.

1 Answer 1


First list all network services to get an overview:

networksetup -listallnetworkservices

Output example:

An asterisk (*) denotes that a network service is disabled.

I renamed my two network services from "Ethernet" to en0 and "Ethernet Adapter (1)" to en1. You have to use your actual network service names of course! If the network service name contains spaces you have to use quotes (e.g. "Apple USB Ethernet Adapter") in the commands below.

To set search domains for a network service use:

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


sudo networksetup -setsearchdomains en0 example.home example.net example

Check with networksetup -getsearchdomains en0:


If you want to add search domains to already existing domains use:

SEARCHDOMAIN=$(networksetup -getsearchdomains en0)
sudo networksetup -setsearchdomains en0 $SEARCHDOMAIN domain1 domain2 ...
  • Thanks. I did edit my post and I am almost done. Just the final part I get an error message. Any help?
    – Fabio
    Jan 12, 2017 at 16:20
  • Thansk. This helps me. In my test, sudo is not needed.
    – Simba
    Sep 19, 2020 at 8:19
  • 2
    Using en0 doesn't work for me (Monterey, 2022), instead I have to use the network service name, e.g. Wi-Fi or "Thunderbolt Ethernet" instead Mar 23, 2022 at 13:49
  • How did this pass review (Apple?) - interface is "en8" but the only argument it recognizes (discovered only with tab completion) is: "AX88179\ USB\ 3.0\ to\ Gigabit\ Ethernet" - because using a description field with embedded spaces makes more sense than the well-known, universally accepted "en/eth/if/..." convention.
    – Bruce Edge
    Aug 7, 2022 at 17:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .