Set new dns for all macs

sabdul
New Contributor II

We found that some of the mac users in the company are using google dns and we would like to set everyone's dns to our dns. Is there a script we can push out via jamf to set DNS on all our macs including wifi/ethernet?

Thanks

2 REPLIES 2

cbrewer
Valued Contributor II

Here's a script I use. I haven't done much with it lately, but I think it still gets the job done.

#!/bin/bash

NetworkServices=`networksetup -listallnetworkservices`

if [[ $NetworkServices =~ "Wi-Fi" ]];then
    networksetup -setdnsservers Wi-Fi empty
    echo "Reset DNS Servers for Wi-Fi"
fi

if [[ $NetworkServices =~ "Ethernet" ]];then
    serviceName=`networksetup -listallnetworkservices | grep "Ethernet" -m 1`
    networksetup -setdnsservers "$serviceName" empty
    echo "Reset DNS Servers for $serviceName"
fi

if [[ $NetworkServices =~ "LAN" ]];then
    serviceName=`networksetup -listallnetworkservices | grep "LAN" -m 1`
    networksetup -setdnsservers "$serviceName" empty
    echo "Reset DNS Servers for $serviceName"
fi

ben_hertenstein
Release Candidate Programs Tester

Just what I was looking for. Thanks!