Adding Search Domains doesn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on
08-01-2017
09:26 PM
- last edited on
03-04-2025
07:54 AM
by
kh-richa_mig
Good Morning,
we use this script to set the Search Domains to our clients but if the clients are ready there is only one search domain in the DNS Settings.
We changed the script like this for example:
Manually specify the DNS entries (separated by space) to be added to each Ethernet port below, add/remove as needed
Manually specify the ports to ignore such as Bluetooth, FireWire, etc.
Enter your own variables below=
DNS="clients.local.domain.de local.domain.de domain.de" #Add your own DNS Searches here on this line#
But this isn't working... Does anybody have an idea whats wrong in this line ?
Many thanks in advance.
Kind regards,
Frank

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 08-02-2017 02:30 AM
I've tried the script and it worked ok. It's a bit hard to tell from the posting what bits are changed. Is it just the DNS variable?
If you could post your modified script with three backticks above and below the code that will format it as a script like this:
#!/bin/sh
my script commands
exit $?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 08-02-2017 11:16 AM
I use this in part of a Defaults script I blast to all new machines or freshly imaged
networksetup setsearchdomains "Ethernet" domain1.domain.com domain2 domain.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 08-03-2017 12:24 AM
Hello,
thanks for your answers.
Thats the script we use we only changed the DNS Variable.....
########################################################!/bin/bash
Ensure we are running this script as root
rootcheck () { if [ "/usr/bin/whoami
" != "root" ] ; then /bin/echo "script must be run as root" exit 0 fi }#####################################
End Functions
Set to the default BASH limiters
IFS=$' 'Manually specify the DNS entries (separated by space) to be added to each Ethernet port below, add/remove as needed
Manually specify the ports to ignore such as Bluetooth, FireWire, etc.
Enter your own variables below=
DNS="clients.local.ergodirekt.de local.ergodirekt.de qv.de" #Add your own DNS Searches here on this line# NoModList="Bluetooth FireWire" NoModList_Pattern=$( echo $NoModList | sed 's/ /|/g' )Set the delimiter to a newline and NOT a space to keep port names whole
Find the identities of the 'en' ports we wish to edit DNS info, filter out the No Mods to be ignored
IFS=$' ' PortList=$(networksetup -listallhardwareports | grep "Device: en" -B 2 | grep "Hardware Port:" | cut -c 16-100 | egrep -v -e $NoModList_Pattern)Now, for each port listed in PortList, add the DNS entries
If an error presents during a config set (missing adapters), don't report the error, 1>/dev/null
for i in $PortList ; do echo "taking action for port ": $i IFS=$' ' sudo networksetup -setsearchdomains "$i" ""$DNS"" 1>/dev/null doneEcho out that we're finished adding the DNS entries to the found ports
echo "Done! The discovered Ethernet ports "$PortList", have been modified"End the script here
exit 0
Kind regards,
Frank
