Created
September 4, 2010 11:59
-
-
Save zipizap/565137 to your computer and use it in GitHub Desktop.
Script to configure dhclient to use as primary DNS the OpenDns servers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DHCLIENTCONF_FILE="/etc/dhcp3/dhclient.conf" | |
#Prepend Opendns name-servers into DHCLIENTCONF_FILE | |
if [ "$(id -u)" -ne 0 ]; then | |
echo "Must be run as root" | |
exit 1 | |
fi | |
if [ "$(egrep '^prepend domain-name-servers' $DHCLIENTCONF_FILE | wc -l)" -ne 0 ]; then | |
echo "There is already a line 'prepend domain-name-servers ...' in $DHCLIENTCONF_FILE - check it" | |
echo "Aborting" | |
exit 1 | |
fi | |
echo " Resume of what's about to happen:" | |
echo " Everytime dhclient executes, the returned DNSs sent by the dhcp-server delete and overwrite the previous-ly existing /etc/resol.conf, leaving only the server-returned DNSs in it" | |
echo " This script will change the configuration file of dhclient (which is $DHCLIENTCONF_FILE), so that dhclient will always include in the resolv.conf, the Opendns servers before the DNSs sent by the dhcp-server" | |
echo "" | |
echo " (press any key to continue, or CTRL-C to abort)" && read | |
echo "" | |
echo "..Starting execution" | |
echo "..Prepend'ing Opendns servers into $DHCLIENTCONF_FILE " | |
echo '' >> $DHCLIENTCONF_FILE | |
echo '#:) Prepend the OpenDns servers into /etc/resolv.conf (which is overwritten everytime dhclient runs)' >> $DHCLIENTCONF_FILE | |
echo 'prepend domain-name-servers 208.67.220.220, 208.67.220.222;' >> $DHCLIENTCONF_FILE | |
echo "..Finished - from the next time dhclient executes, it will always use the Opendns as first DNS option, and use the server-returned DNSs as secondary option" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment