#!/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