Clear/Lock DNS Settings

TomDay
Release Candidate Programs Tester

We use OpenDNS Umbrella client for web filtering on some student machines. Brief background info is that we have 2 DNS servers that are pushed out via DHCP (the DNS servers are the IP of the OpenDNS HA servers that allow web access). I've found a few students manually adding DNS servers like 8.8.8.8 etc to avoid using these pushed DNS servers. Looking for a way to lock the DNS tab of any service in Network preferences and then if I can get that to work, clear out any manual entries that may have been added. Locking the Network Preferences pane will probably not be an option, I'm hoping to go a little deeper.

4 REPLIES 4

Kumarasinghe
Valued Contributor

To clear all manually entered search domain entries:

#!/bin/bash

declare -x SearchDomains="empty"

OLDIFS="$IFS"
     IFS=$'
'

declare -x nserviceslist=( $(/usr/sbin/networksetup -listallnetworkservices | grep -Ei '(Ethernet|Wi-Fi|AirPort|Bridge)') )

IFS="$OLDIFS"

tLen=${#nserviceslist[@]}

echo "Network Services List:"
     for (( i=0; i<${tLen}; i++ ));
     do
     /usr/sbin/networksetup -setsearchdomains "${nserviceslist[$i]}" "$SearchDomains"
     /bin/echo "${nserviceslist[$i]} is now configured with $SearchDomains as DNS Search Domain."
     done

exit 0

TomDay
Release Candidate Programs Tester

Thx @Kumarasinghe, I'll play with this today or Monday

rcastorani
New Contributor II

@tommyday Here is the script I use to basically just remove the DNS view from inside the preference pane:

#!/bin/sh

# Greys out the Change Password button
rm /System/Library/PreferencePanes/Accounts.prefpane/Contents/Resources/en.lproj/ChangePasswordController.nib

# Remove DNS view
rm /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/en.lproj/ANPAdvancedDNSView.nib

# Remove Proxy view
rm /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/en.lproj/ANPAdvancedProxyView.nib

# Remove WINS view
rm /System/Library/PreferencePanes/Network.prefPane/Contents/Resources/en.lproj/ANPAdvancedWINSView.nib

eatkins
New Contributor II

anyone have any more up-to-date recommendations for this request?