Posted on 06-18-2015 03:13 AM
Hi All,
I have created a configuration profile to add our VPN settings but for the life or me, I cannot find a way to add two DNS servers and a custom search domain to this. Any Ideas? Also, we have a remote office and often with Yosemite, when using ethernet, it does not auto populate the DNS servers and the same search domain there either. Needless to say it has a different IP range so when any computer is plugged into any ethernet cable, it loses the DNS + search domains needed.
This then means I have to WALK alllllll the way over there and set it up :(
Any help on this would be greatly appreciated and also save me wearing out my shoes!
Posted on 06-18-2015 06:14 AM
Hey Phil,
you could add search domains via script.
/usr/sbin/networksetup -setsearchdomains Ethernet test.domain.de
Posted on 06-18-2015 06:18 AM
I've got a script for setting up DNS search domains on Ethernet interfaces available from here:
It could likely be adapted to also provide DNS server settings.
Posted on 06-18-2015 07:02 AM
I use the following script, then apply the script via policy.
sudo networksetup -setsearchdomains "Ethernet" "xxxxx.net" "xxxxx.com" "xxxxx.edu"
delay 5
sudo networksetup -setsearchdomains "Wi-Fi" "xxxxx.net" "xxxxx.com" "xxxxx.edu"
Posted on 06-19-2015 07:29 AM
Agreed on the previous replies. Be aware that you need to identify the NIC # if the machine has multiples (aka. "Ethernet 1" or "Ethernet 2")
Posted on 06-26-2015 12:36 PM
@rtrouton Thanks for that script! You just saved me the trouble of writing it. I tweaked it slightly to include Wi-Fi, other than that it fits our need perfectly.
Posted on 01-07-2016 12:58 PM
I used this script today and I see it's working for ethernet interface but not for Wi-Fi. Is that how it's supposed to work? I guess I could see an issue with Wi-Fi if it pulls from different wi-fi organizations (work, home. restaurant, etc) and no Locations were set except the default. Just want to check and make sure.
Posted on 01-07-2016 01:05 PM
@jonathanla I made this tweak to Rich's script so that it works on Wi-Fi as well as a few different network interface names that are in use by our client machines. You would need to change line 31 of the script to something like this:
ethernet_interface=($(networksetup -listallnetworkservices | awk '/Ethernet/ || /Corp/ || /Wi-Fi/ || /CORP/'))
Posted on 01-07-2016 01:07 PM
The script is just for Ethernet, although you could change it to WiFi if needed by changing the awk '/Ethernet/'
on line 31.
Posted on 01-08-2016 01:46 PM
Thanks everyone. I modified it and it's running.
Posted on 01-20-2016 09:52 AM
This helped me a TON! Thanks as always @rtrouton ...@stevehahn your tweak was very helpful as well!
Posted on 01-20-2016 12:05 PM
Hey @rtrouton ... your script looks similar to mine!
https://github.com/franton/Set-DNS-info
You can specify the network service name with my script, so all ethernet or all vpn services ...
Posted on 09-28-2016 07:11 AM
Thanks for these. Very helpful, but I didn't understand if there's a place in this script, or the others posted from JAMF (id=14892 and id=801). Once these search paths are entered, are they hardware based, or also location based? Meaning the Wi-Fi Search path in the office is different when at home or traveling and I don't want those search paths on those locations, but only Wi-Fi at our work location.
Any clarification would be appreciated.
Posted on 11-16-2016 07:27 AM
In our company, we decided to go with DHCP option 119 : this way, when a Mac connects to the LAN, you get immediately the list of search suffixes that are valid/useful for the office where you are currently physically located.
So when people travel and connect to our LAN in another country for example, they immediately get the correct local list of suffixes for that country. This solution works well for Macs, as well as for iOS devices, and works obviously even if the devices are not enrolled. It requires the network team to maintain a different list for every "DHCP subnet group", but once done you are good.
Sure, you cannot do much when people are at home, but at home you probably do not need these search suffixes (if you do, then use FQDNs :-). )
Posted on 09-13-2018 07:36 AM
I have found that sending the command with more than 3 search domains creates search domans with quotes around them "xxx" on each domain after the 3rd. How would one prevent this?
Example:
sudo networksetup -setsearchdomains "Ethernet" "xxxxx.net" "xxxxx.com" "xxxxx.edu" "xxxxx.edu" "xxxxx.edu"
Creates:
xxxxx.net
xxxxx.com
xxxxx.edu
"xxxxx.edu"
FIXED: (duh)
networksetup -setsearchdomains Ethernet xxx.edu xxx.edu xxxx.edu x.edu xxx.com xxx.edu