Distroname and release: Debian Squeeze
Static DNS / Protect the resolv.confDNS servers are located in the /etc/resolv.conf file on linux systems, and unfortunately this file seems to be overwritten with every reboot, or DHCP lookup, which is quite frustrating in situations where ou want to use another DNS server.
There are severel ways of protection the resolv.conf file for being overwritten by reboot or like in this first example, it is possible to control it completely, if you want to use another DNS than the DHCP server gives you.
Using dhclientUsing the dhclient it is possible to control the DNS entries. Find the following line, and edit as your needs.
In this first example, we will prepend the domain-name-servers. Meaning that this will be added after the DNS from the DHCP in the /etc/resolv.conf
other examples are provided as well.
I would defiantly recommend this solution, than the one provided below (immunize), because this one should work on all systems and are not restricted to the filesystem.
Find the prepend domain-name-servers line in the /etc/dhcp3/dhclient.conf file.
Most likely the entry is commented with an #. Remove the mark, or add a new line. Add the DNS server or servers seperated by ,.
/etc/dhcp3/dhclient.conf prepend domain-name-servers 188.8.131.52, 184.108.40.206;After the changes renew the IP to recieve the new DNS entries.
#ifdown eth0 && ifdown eth0Afterwards the output of the resolv.conf file, should be something like this.The two last ones are the ones from the DHCP server.
Output of prepend domain-name-servers 220.127.116.11, 18.104.22.168
/etc/resolv.conf nameserver 22.214.171.124 nameserver 126.96.36.199 nameserver 192.xxx.xxx.xxx nameserver 193.xxx.xxx.xxx
Other examplesappend, will add it the entries to the end of the file instead of first as we did with the prepend option above.
/etc/dhcp3/dhclient.conf append domain-name-servers 188.8.131.52, 184.108.40.206;Output of append domain-name-servers 220.127.116.11, 18.104.22.168
/etc/resolv.conf nameserver 192.xxx.xxx.xxx nameserver 193.xxx.xxx.xxx nameserver 22.214.171.124 nameserver 126.96.36.199With supersede it will replace all DNS entries recived by the DHCP, which is most likely what you are looking for ?.
/etc/dhcp3/dhclient.conf prepend domain-name-servers 188.8.131.52, 184.108.40.206;Output of supersede
/etc/resolv.conf nameserver 220.127.116.11 nameserver 18.104.22.168After the changes run, if ofcourse the connected adapter is eth0:
#ifdown eth0 && ifup eth0Next you can control the settings in the /etc/resolv.conf file
#cat /etc/resolv.conf nameserver XXXXXXXXXXXX nameserver 22.214.171.124 nameserver 126.96.36.199
Immunize the fileI would almost categorize this as an workaround.
On and only on ext2 and ext3 filesystems it is possible to immunize the resolv.conf file with chattr, so that no data is written to the file.
Note that this is not the same as removing the rights with chmod, since the file still can be overwritten, even though that all rights are removed from the file!
First make the changes to the file and save it.
/etc/resolv.conf nameserver 188.8.131.52 nameserver 184.108.40.206After the changes immunize the file.
chattr -i /etc/resolv.confTo remove the immunize attribute simply use the + parameter
chattr +i /etc/resolv.conf