Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
1  
What OS are you running? –  gabe. Feb 14 '12 at 3:15
    
I am using Debian 6. –  Village Feb 14 '12 at 6: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 Feb 17 '12 at 17:43
    
I have not found the answer yet. –  Village Feb 23 '12 at 23:58

5 Answers 5

up vote 4 down vote accepted

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.

share|improve this answer
1  
You can specify nameservers in networkmanager configs per connection basis. –  Manwe Feb 14 '12 at 10:06
    
That's what I implied, yes. –  Shadur Feb 14 '12 at 10:38
    
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 Feb 24 '12 at 5: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).
share|improve this answer
1  
I think resolvconf is being phased out of squeeze in favor of NM. –  Shadur Feb 14 '12 at 10:38
1  
@Shadur I'm not seeing any such mention in wiki.debian.org/… –  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.

share|improve this answer

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
share|improve this answer
    
My Internet connection does not use DHCP. –  Village Feb 23 '12 at 23:58

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.