My ISP asked me to use custom nameserver
settings. I have placed these in /etc/resolv.conf
. Unfortunately, every time I reboot the computer, the contents of this file is changed. To connect to the Internet, I must first edit that file. How can I ensure that this file does not change?

- 31,260

- 5,035
- 15
- 50
- 84
-
1What OS are you running? – gabe. Feb 14 '12 at 03:15
-
I am using Debian 6. – Village Feb 14 '12 at 06:07
-
Just as a friendly bit of advice, if any of the answers below turned out to be the one you needed, please accept one. It's good etiquette and it makes people more likely to try to answer your questions. – Shadur-don't-feed-the-AI Feb 17 '12 at 17:43
-
I have not found the answer yet. – Village Feb 23 '12 at 23:58
5 Answers
In all likelihood the culprit is NetworkManager -- it rebuilds /etc/resolv.conf
on startup/shutdown and whenever your managed network connections change.
Your best bet, unless you want to strip parts of your install out of your system, is to add your user to the netdev
group (sudo adduser myuser netdev
will do the trick) and then using network-manager-gnome
or network-manager-kde
depending on your preferred flavor to manage settings and specify your DNS servers. A useful tutorial can be found here.
Alternately, you can dig into /etc/network/interfaces
and specify that the network connection you use to connect to the internet is not to be managed by NetworkManager, then add the keyword dns-nameservers
to the stanza for that interface.

- 31,260
-
1You can specify nameservers in networkmanager configs per connection basis. – Manwe Feb 14 '12 at 10:06
-
-
I do not use GNOME, and I could not find any NetworkManager package anywhere in the
apt
database. – Village Feb 23 '12 at 23:57 -
It's called
network-manager
in the apt package database. – Shadur-don't-feed-the-AI Feb 24 '12 at 05:44
Take a look at the resolvconf
package -- its purpose is to intercept resolv.conf changes (e.g. by DHCP clients). It can run small scripts when that happens, and it can prepend, append, or override settings written into resolv.conf
Resolvconf is a framework for keeping up to date the system's
information about name servers. It sets itself up as the intermediary
between programs that supply this information (such as ifup and
ifdown, DHCP clients, the PPP daemon and local name servers) and
programs that use this information (such as DNS caches and resolver
libraries).

- 2,045
-
1I think
resolvconf
is being phased out of squeeze in favor of NM. – Shadur-don't-feed-the-AI Feb 14 '12 at 10:38 -
1@Shadur I'm not seeing any such mention in http://wiki.debian.org/NetworkConfiguration#Defining_the_.28DNS.29_Nameservers – hhaamu Feb 14 '12 at 11:31
If you are using ppp to connect to your isp, then pppd
will run /etc/ppp/ip-pre-up
after it connects, but before bringing up the network interface. Most systems also have an /etc/ip-up
that gets run after the network interface is brought up, and that is usually a script that runs everything in the directory /etc/ip-up.d/
. Also, most systems already have a script in /etc/ip-up.d/
that takes care of setting up /etc/resolv.conf
. You can use any of these scripts to make sure nameservers are set up.

- 46,081
If you're using the Dynamic Host Configuration Protocol (DHCP), then it will configure your network settings automatically, which includes the address, the gateway and the nameserver, among others. When this happens, resolv.conf
, or any other place for this kind of network configuration, gets changed, by design.
Check your system documentation to know what's the correct way to provide static DNS settings. For example, right now my resolv.conf
reads
# Generated by dhcpcd from eth1
# /etc/resolv.conf.head can replace this line
[...]
# /etc/resolv.conf.tail can replace this line

- 13,495
For anyone who might stumble upon this issue: I fixed it in my router.
My computer is connected to my router, which is connected to my modem which goes ultimately to my provider.
In resolv.conf
I found the address of my router as the first nameserver and then the address of my modem. Since my router didn't have any nameserver tables it wouldn't give any useful response, but it took quite some time before it gave a response at all, so each time I did a resolve request, it tried my router first which took a lot of time, then it would go to my modem.
So I needed some way to have my modem address as first nameserver in resolv.conf
. Now I just used DHCP in Debian so I figured my router must give me this wrong nameserver. So I looked into my router configuration and found that I could specify static DNS servers (I have a Linksys router). I set the address of my modem in there and now after every reboot Debian has my modem address as first nameserver in resolv.conf
!
Hope that helps anyone.