OS X Sys Prefs > Network > DNS > Search Domains

johnklimeck
Contributor II

Anyone have a way for the "proper and correct" Search Domain name to appear in OS X Sys Prefs > Network > DNS > Search Domains.

My last gig (after DNS was upgraded and corrected, with Infoblox hardwar, etc.), this info appeared automatically with the "new" and correct DNS Servers (names and IPs), and the corresponding Search Domain. All of which are "greyed" and pushed out (I suspect via DHCP).

In my current environment we are picking up the old "legacy" Windows 2003 domain DNS servers with no Search Domain, Although OS X is adding an entry just called "local".

I can enter the correct domain name and this resolves a host of things, but its the manual entry part. Any ideas on where this info lives in OS X.

Hopefully the network people will implement the new DNS soon.

thanks in advance,

John

1 ACCEPTED SOLUTION

nkalister
Valued Contributor

the actual command to set the domains is

/usr/sbin/networksetup -setsearchdomains <Interface name> <domains to be added>

substitute the network interface for <Interface name>, i.e. Wi-Fi or Ethernet or whatever.
for the list of domains to be added, put them into the command with a space between each, no commas- i.e. example.company.com example2.company.com example3.company.com

View solution in original post

9 REPLIES 9

stevewood
Honored Contributor II
Honored Contributor II

Take a look at Rich Trouton's FirstBoot scripts:

https://github.com/rtrouton/rtrouton_scripts/tree/master/rtrouton_scripts/first_boot

He has the method for setting search domain via script for 10.6 thru 10.8.

You can setup a policy to run either once on all of your computers, or at each login or something, to reset your search domains.

This what you are looking for?

gregp
Contributor

Ideally, the search domains should be pushed out correctly from the DHCP servers. But often that is not happening for whatever reason (perhaps its shoved out via AD GPO instead??).

We have only one domain of 3 or so that we need coming from DHCP, so we also have a script to populate this upon the first boot after imaging. Ours sets up the search domains, DNS servers, auto proxy and I think a couple of other things. We have another script that does the pmset stuff.

Rich's script is very nice and rather comprehensive.

nkalister
Valued Contributor

the actual command to set the domains is

/usr/sbin/networksetup -setsearchdomains <Interface name> <domains to be added>

substitute the network interface for <Interface name>, i.e. Wi-Fi or Ethernet or whatever.
for the list of domains to be added, put them into the command with a space between each, no commas- i.e. example.company.com example2.company.com example3.company.com

johnklimeck
Contributor II

Thanks stevewood, nkalister

Took me a few minutes and I was able to extrapolate the command you posted nkalister. Works great.

Thanks again,

John

Not applicable

Remember if you're going to script the networksetup command that AirPort has been renamed to Wi-Fi since 10.7, and Mac Pros will report "Ethernet 1" versus "Ethernet 2" by default..

franton
Valued Contributor III

I came up with a script that allows you to specify a network interface, then it searches for all occurrences and programs them up. This allows you to neatly deal with external ethernet adaptors without reprogramming.

#!/bin/sh

# Set Search Domains
# Author: r.purves@arts.ac.uk
# Version 1.3 : 24-10-2012

# Set variables up here
# Casper reserves $1 to 3 for itself, so we have to use $4 onwards.
# So when calling this script, use the following fields of information:
# Field 4: Name of a Network Service (e.g Ethernet)
# Field 5: First search domain address. (eg. domain.local)
# Field 6: Second search domain address. (eg. domain.local)

searchNetwork="$4"
searchDomain1="$5"
searchDomain2="$6"

# Let's check to see if we've been passed the Search Domain details in field 5 & 6.

if [ "$searchNetwork" == "" ]; then
    echo "Error:  No network service name in parameter 4 was specified."
    exit 1
fi

if [ "$searchDomain1" == "" ]; then
    echo "Error:  No search domain in parameter 5 was specified."
    exit 1
fi

if [ "$searchDomain2" == "" ]; then
    echo "Error:  No search domain in parameter 6 was specified."
    exit 1
fi

# We're going to be doing clever things with $IFS
# (internal field separator)
# So we need to save IFS so we can change it back later 
OLDIFS=$IFS
IFS=$'
'

# Let's start setting the search domains

# Read the output of the networksetup command
# Grep that output through the specified service name
# Then read all of it into an array
NetServiceArray=($( networksetup -listallnetworkservices | grep $searchNetwork ))

# We'll stop being clever with $IFS and put it back the way it was
IFS=$OLDIFS

# What's the length of the array? We need it for the following loop
tLen=${#NetServiceArray[@]}

# This is the bit that actually does the work
# Loop around the array and process the contents
for (( i=0; i<${tLen}; i++ ));
do
  echo "Network Service name to be configured - " "${NetServiceArray[$i]}"
  echo "Specified Search Domains addresses - " $searchDomain1 $searchDomain2
  networksetup -setsearchdomains "${NetServiceArray[$i]}" $searchDomain1 $searchDomain2
done

exit 0

MORPHO
New Contributor

Hi hello

Good script but tell me how i can do for execute this script for the Active Network Interface ( from report casper jamf )

Thanks

franton
Valued Contributor III

You specify the interface name when calling the script. See the notes embedded in it.

I have newer version that does DNS and Search Domain settings at https://github.com/franton/Set-DNS-info

acdesigntech
Contributor II

@gregp, Yes they should be pushed through DHCP so that ALL OSes can recognize the search domains, but it's easier for Windows admins to push through GPO, so that's how most environments with a Windows backbone are run. Apparently the DNS suffixes have to be formatted EXACTLY when pushed through DHCP and that does not happen by default so requires some finessing by the Windows guys.

Not sure how easy/hard/complex it is to do this with a network appliance, but here we use Windows servers to push DHCP so...