Skip to main content
Solved

Adding in additional DNS server and Search Domains


Forum|alt.badge.img+4

I've been tasked with implementing this change on some remote users. I've had a quick scout around and can't see an easy way of doing this. Anyone got any ideas?

Best answer by rockpapergoat

do these hosts use dhcp? if so, add them to your dhcp server config, and you won't need to touch the clients.

if they're assigned static IPs, you can use /usr/sbin/networksetup to do the job. i wouldn't go that route unless it's the only option.

View original
Did this topic help you find an answer to your question?

7 replies

Forum|alt.badge.img+13
  • Contributor
  • 427 replies
  • Answer
  • March 5, 2012

do these hosts use dhcp? if so, add them to your dhcp server config, and you won't need to touch the clients.

if they're assigned static IPs, you can use /usr/sbin/networksetup to do the job. i wouldn't go that route unless it's the only option.


Forum|alt.badge.img+4
  • Author
  • Contributor
  • 23 replies
  • March 5, 2012

Thanks. Makes total sense just need to speak to their comms guy now.


Forum|alt.badge.img+20
  • Valued Contributor
  • 732 replies
  • March 5, 2012

Here is the script I use:

#!/bin/sh

##################################
# Output: Setting Search Domains #
##################################

##################################
# Do Not Modify Below This Line  #
##################################

/usr/sbin/networksetup -setsearchdomains "Ethernet" "yourcompany.com" "sub.yourcompany.com"
/usr/sbin/networksetup -setsearchdomains "Ethernet 1" "yourcompany.com" "sub.yourcompany.com"
/usr/sbin/networksetup -setsearchdomains "Ethernet 2" "yourcompany.com" "sub.yourcompany.com"
/usr/sbin/networksetup -setsearchdomains "Airport" "yourcompany.com" "sub.yourcompany.com"

Forum|alt.badge.img+1
  • New Contributor
  • 4 replies
  • October 16, 2013

I am trying to add multiple search domains to the Ethernet and Wi-Fi adapter. Here are the scripts that I am using - if I do this on the local client it works great, but once I created a script inside jss and created a policy to run that script I get an error

sudo -a -networksetup -setsearchdomains "Ethernet" domain1.edu domain2.edu domain3.edu
sleep 1
sudo -a -networksetup -setsearchdomains "Wi-Fi" domain1.edu domain2.edu domain3.edu

Am I missing something in the script that I created in jss in why this isn't working?


Forum|alt.badge.img+18
  • Valued Contributor
  • 1007 replies
  • October 16, 2013

my guess is there is not a -a option for sudo.
and -networksetup is not an option it is a command that should not have the - so remove -a - from those lines and something more useful might happen.
Also if you are running through the JSS then its already running as root so you dont need sudo at all.


Forum|alt.badge.img+1
  • New Contributor
  • 4 replies
  • October 16, 2013

Thank you thank you thank you nessts - those tips worked.


Forum|alt.badge.img+1
  • New Contributor
  • 1 reply
  • June 6, 2023
Matt11 wrote:

Here is the script I use:

#!/bin/sh

##################################
# Output: Setting Search Domains #
##################################

##################################
# Do Not Modify Below This Line  #
##################################

/usr/sbin/networksetup -setsearchdomains "Ethernet" "yourcompany.com" "sub.yourcompany.com"
/usr/sbin/networksetup -setsearchdomains "Ethernet 1" "yourcompany.com" "sub.yourcompany.com"
/usr/sbin/networksetup -setsearchdomains "Ethernet 2" "yourcompany.com" "sub.yourcompany.com"
/usr/sbin/networksetup -setsearchdomains "Airport" "yourcompany.com" "sub.yourcompany.com"

Thank for this - I ended up reworking it for our needs to include DNS servers as well / had to make a minor adjustment for systems with a single Ethernet interface but that was pretty easy once the dual interface systems test proved positive results:

#!/bin/bash

##################################
# Output: Setting Search Domains #
##################################

##################################
# Do Not Modify Below This Line #
##################################

primary_dns="X.X.X.X"
secondary_dns="X.X.X.X"
tertiary_dns="X.X.X.X"

services=("Ethernet 1" "Ethernet 2" "Wi-Fi")

for service in "${services[@]}"; do
/usr/sbin/networksetup -setdnsservers "$service" "$primary_dns" "$secondary_dns" "$tertiary_dns"
/usr/sbin/networksetup -setsearchdomains "$service" "searchdomain1.com" "searchdomain2.com"
done

just swap in your DNS server addresses and Search Domains for the place holders and scope this to any dual ethernet  systems

 

For single Ethernet  systems the adjustment is:

services=("Ethernet" "Wi-Fi")

It is really that simple

Tested this on macOS 10.15 through 13.3 systems and it works 

If you are not sure about the network interfaces on a given target system - remote in (if you are able to) and run the following in Terminal.app

networksetup -listallnetworkservices


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings