Change DNS "Search Domains" via Script

ds_support
New Contributor III

Hello Jamf Community,

I am looking for a script, to change the DNS "Search Domain" to .local on Wi-Fi and Thunderbolt Ethernet.

I try a few comands but no one works...

Hope everyone can help me.

Many Thanks
Christian

2 ACCEPTED SOLUTIONS

thoule
Valued Contributor II
/usr/sbin/networksetup -setsearchdomains "Wi-Fi" .local

And networksetup -listallnetworkservices can give you a list of network interfaces to tackle. Just put it into an array and loop through them.

View solution in original post

ds_support
New Contributor III
/usr/sbin/networksetup -setsearchdomains "Wi-Fi" .local And networksetup -listallnetworkservices can give you a list of network interfaces to tackle. Just put it into an array and loop through them.

Hello thoule,

many Thanks for your help! This script works great! With this script, the login is in the AD is 80% faster.
I enter the following script in Casper Suite:

#!/bin/bash

/usr/sbin/networksetup -setsearchdomains "Thunderbolt Ethernet" .local
/usr/sbin/networksetup -setsearchdomains "Wi-Fi" .local

Many Thanks,
Christian

View solution in original post

15 REPLIES 15

thoule
Valued Contributor II
/usr/sbin/networksetup -setsearchdomains "Wi-Fi" .local

And networksetup -listallnetworkservices can give you a list of network interfaces to tackle. Just put it into an array and loop through them.

ds_support
New Contributor III
/usr/sbin/networksetup -setsearchdomains "Wi-Fi" .local And networksetup -listallnetworkservices can give you a list of network interfaces to tackle. Just put it into an array and loop through them.

Hello thoule,

many Thanks for your help! This script works great! With this script, the login is in the AD is 80% faster.
I enter the following script in Casper Suite:

#!/bin/bash

/usr/sbin/networksetup -setsearchdomains "Thunderbolt Ethernet" .local
/usr/sbin/networksetup -setsearchdomains "Wi-Fi" .local

Many Thanks,
Christian

franton
Valued Contributor III

Here's something I wrote a few years ago.
Set DNS Info

This has the benefit of you only specify "Ethernet" and it will do all forms of Ethernet service. e.g. Ethernet 1 and Ethernet 2 on Mac Pros. Thunderbolt Ethernet on tb displays. USB ethernet for laptops etc etc.

burdett
Contributor II

Anyone else still using this Set DNS Info script that franton wrote? The new macbooks (dongles) are not being picked up. It look like these adapters are identified as LAN rather than Ethernet. Any Ideas on how to update the Set DNS Info script to pick up these new Lan interfaces?

ChadL3
New Contributor II

I'm having issues adding the new USB-C adapters. They show up in the hardware ports as USB 10/100/1000 LAN, my script doesn't seem to recognize them and skips over. It adds WI-FI and Thunderbolt just fine. Any ideas?

franton
Valued Contributor III

I can alter the scripts to cope. I need @burdett and @ChadL3 to provide screen grabs of Network pane showing the exact name of the adaptors.

jhalvorson
Valued Contributor

Here's a list of common adapter ID's we've seen.

USB 10/100/1000 LAN

(covers a few Startech, Kanex, and HP adapters)

Belkin USB-C LAN

(covers the White Belkin adapter sold by Apple)

USB Gigabit Ethernet
USB Ethernet
Apple USB Ethernet Adapter
Thunderbolt Ethernet
Display Ethernet

I include these in a Self Service script that helps add network ports for times when the user does not have admin rights.

franton
Valued Contributor III

Ok so what you would do with my script is two policies. One that you call the script with "Ethernet" and another to call with "LAN". The script is looking for key names to process, so that's the easiest way forward.

ChadL3
New Contributor II

Here is my script.. That doesn't work!

else if [ ${dev} == "USB 10/100/1000 LAN" ]; then echo "USB 10/100/1000 LAN has been configured with Domain suffixes" networksetup -setsearchdomains "USB 10/100/1000" mydomains.com

**Policy Log**

USB-10/100/1000-LAN has been configured with Domain suffixes
USB-10/100/1000-LAN is not a recognized network service.
** Error: The parameters were not valid.

Wi-Fi

Wi-Fi has been configured with Domain suffixes

burdett
Contributor II

@franton I tried your new script but I'm getting the following errors;
line 66: syntax error near unexpected token `<'
line 66: `done < <( networksetup -listallnetworkservices | grep -E "$searchNetwork" )'

For testing I'm not running these form JAMF so I modified the following; searchNetwork="Ethernet"
searchDomain1="my.1search.domain.edu"
searchDomain2="my.2search.domain.edu"
PrimaryDNS="xxx.xxx.xxx.xxx"
SecondaryDNS="xxx.xxx.xxx.xxx"

franton
Valued Contributor III

@burdett The script on my Github is working for me. I'm not sure what you are doing wrong. Please make sure your Jamf policy is calling it with the correct info and the script has been properly copied into your Jamf system.

jhalvorson
Valued Contributor

-deleted this post-

jhalvorson
Valued Contributor

@franton I am also seeing an error with line 66.
syntax error near unexpected token `<'
line 67: `done < <( networksetup -listallnetworkservices | grep -E "$searchNetwork" )'

done < <( networksetup -listallnetworkservices | grep -E "$searchNetwork" )

Like @burdett, I am setting the variables within the script and not using Jamf when testing out the script.

franton
Valued Contributor III

I'll be honest, that only occurs for me if the $searchNetwork variable is blank.

This works for me.

burdett
Contributor II

@jhalvorson, I did some digging around and I found Erik Berglund's script, "modifyNetworkServiceOrder" on github at;
https://github.com/erikberglund/Scripts/blob/master/random/modifyNetworkServiceOrder/modifyNetworkSe... I noticed Erick's script started with #!/usr/bin/env bash rather then #!/bin/sh used in @franton script. It's not clear to me the difference but this resolved the error I was having with franton's script.