Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I need help figuring out why my resolv.conf keeps changing to this, causing me to not be able to access the outside internet and only the local network:

$ cat /etc/resolv.conf
nameserver 192.168.16.1
domain localdomain
search localdomain

I thought I fixed it by getting rid of the loopback interface and adding in the eth0 interface in /etc/network/interfaces with the instructions on jontsai's posterous blog.

I've tried things like doing:

$ sudo ifconfig eth0 down
$ sudo ifconfig eth0 up
$ sudo /etc/init.d/networking restart
$ sudo dhclient

And then things would work temporarily, and eventually the nameserver in resolv.conf would get reverted again.

P.S. I also posted this on ubuntuforums.


Edit: There is at least one other program besides NetworkManager that's writing to resolv.conf, and I know this because when I refresh NetworkManager, the resolv.conf file that gets generated has a comment that says # Generated by NetworkManager, and the version that it keeps changing to does not.

So I am trying this:

while true; do echo listening; lsof | grep /etc/resolv.conf; echo sleeping; sleep 1; done


Edit 2:

Adding output of files:

$ cat /etc/network/interfaces 
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

No such file as /etc/NetworkManager/NetworkManager.conf

$ sudo cat /etc/NetworkManager/system-connections/Auto\ Ethernet 

[connection]
id=Auto Ethernet
uuid=#######omitted#######
type=802-3-ethernet
autoconnect=true
timestamp=1314377063

[ipv4]
method=auto
ignore-auto-routes=false
ignore-auto-dns=false
dhcp-send-hostname=false
never-default=false

[802-3-ethernet]
speed=0
duplex=full
auto-negotiate=true
mtu=0

[ipv6]
method=ignore
ignore-auto-routes=false
ignore-auto-dns=false
never-default=false
share|improve this question
    
I suspect either a Network Manager bug, or more likely a misconfiguration. What version of Ubuntu are you running? Do you have the resolvconf package installed? Post the contents of /etc/network/interfaces, /etc/NetworkManager/NetworkManager.conf and /etc/NetworkManager/system-connections/*. –  Gilles Aug 26 '11 at 20:52
    
I'm running 10.04, no resolvconf package. At some point, my DSL modem was going bad (behind router) while my local network was fine, so I might have tried installing nscd or dnsmasq--they're uninstalled now, but it might have left some artifacts that are interfering? –  jontsai Aug 27 '11 at 1:19
    
Okay, I just rebooted my computer for the first time in 3 weeks, and I think the problem went away. o_O –  jontsai Aug 27 '11 at 2:28
    
Not sure, but I think there was some issue with DHCP server on vmnet1 or vmnet8 (NAT and Host-Only) –  jontsai Aug 27 '11 at 2:46
    
This whole discussion is of diminished relevance since Ubuntu 12.04 which introduced resolvconf in the base system, fundamentally changing the way resolv.conf is handled. –  jdthood Dec 7 '12 at 8:21

6 Answers 6

I disable the update of resolv.conf by creating a file called "disable_make_resolv_conf" in /etc/dhcp3/dhclient-enter-hooks.d

#!/bin/sh
make_resolv_conf(){
}

It replaces the standard function by the same name that's responsible for the resolv.conf refresh.

share|improve this answer

(This answer contains ways to investigate what's going on. I may be able to give an actual solution if you use these methods to gather and provide more information.)

A possible trigger for the seemingly spontaneous updates to /etc/resolv.conf is when your DHCP lease is renewed. Check how long you get DHCP leases for (this should appear in the system logs, I think in /var/log/syslog).

You can use auditd Install auditd to find out what modifies the file. Start the daemon (sudo service auditd start) and tell it to watch for modifications to that file:

sudo auditctl -w /etc/resolv.conf -p w

Audit logs are in /var/log/audit/audit.log. You'll see the time the file was modified and the name of the program that modified it.

If you have the resolvconf package installed, Network Manager may be stepping on its toes. Try bringing all network interfaces down, then stop Network Manager (sudo service network-manager stop), then restart it.

share|improve this answer
    
I believe you are right about DHCP releases. You can change the DHCP settings in the network manager as follows: Run nm-connection-editor in your terminal. Select your interface and hit edit. Under IPv4 settings there should be a method called only DHCP adresses (or something similar). If I'm not mistaken this will allow you to obtain IP adresses through DHCP but not nameservers (you can specify them in the fields below). –  Christian Skjødt Aug 26 '11 at 21:45
    
I set my router to map MAC address to static IPs, so the DNS lease is for a long time. The auditctl line doesn't work for me, and I believe that the service name for Network Manager is network-manager (includes the hyphen). I didn't have a resolvconf package installed, but I had stuff inside the /etc/resolvconf/ folder, and when I compared it to another Ubuntu machine, it didn't have it, so I installed and uninstalled the package, and manually removed that folder. /etc/resolv.conf just got rewritten again, so I think getting auditctl to work would be very helpful. –  jontsai Aug 27 '11 at 1:07
    
@jontsai The presence of /etc/resolvconf is normal even if you don't have the resolvconf package, some packages drop hooks in there, and these hooks are only used if resolvconf is installed. I've fixed the auditctl line, in case the problem appears again. –  Gilles Aug 27 '11 at 8:54
    
I liked the idea of user auditd to find out what was editing the file, but it looks like it get started after the file is already modified. –  Peter Sankauskas Nov 3 '11 at 1:30

You can make static additions to /etc/resolv.conf. Those additions could override the things that are being automatically added.

First, install the resolvconf package.

Then, press Alt+F2 and run gksudo nautilus. Open /etc/resolvconf/resolv.conf.d/head if you want to add to the start of the file; open /etc/resolvconf/resolv.conf.d/tail if you want to add to the end. Make your changes, save/close the files, and then run sudo resolvconf -u to apply the changes.

(Sorry that I don't remember if the settings at the start or end of the file have the highest priority.)

share|improve this answer

I had the exact same problem - resolv.conf would be rewritten every time the server was rebooted.

It was caused by DHCP. To set resolv.conf to what I want it to be, I edited /etc/dhcp/dhclient.conf and added the following:

supersede domain-name "my.domain.com";
prepend domain-search "my.domain.com";

You can actually control quite a bit about your resolv.conf file by making changes to this.

Hope it helps.

share|improve this answer
1  
This would be the cleanest solution but for some reason it stopped working on my systems a few years back. I've been stuck with disabling resolvconf script or chattr +i /etc/resolv.conf ever since. –  Tronic Jul 9 '13 at 12:57

Open up a terminal and type

sudo chattr +i /etc/resolv.conf

the +i takes care that the file wont be reseted on a boot even by root.

To undo the above

sudo chattr -i /etc/resolv.conf

For more

man chattr
share|improve this answer

Another option that I've had some luck with involves using resolvconf.

Add any entries to this file:

/etc/resolvconf/resolv.conf.d/base

And they will be added to the /etc/resolv.conf.

Thanks to this Ask Ubuntu posting: How do I include lines in resolv.conf that won't get lost on reboot?

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.