6

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?

Village
  • 5,035
  • 15
  • 50
  • 84

5 Answers5

5

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.

3

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).
hhaamu
  • 2,045
2

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.

Shawn J. Goff
  • 46,081
1

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
njsg
  • 13,495
1

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.

Anthon
  • 79,293
gitaarik
  • 559