Ubuntu: resolv.conf keeps getting reset by something



Question:

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  


Solution:1

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.)


Solution:2

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.


Solution:3

(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.


Solution:4

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  


Solution:5

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.


Solution:6

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?


Solution:7

Late at this but I will post my case as it was different from all of the above.

In my case, /etc/resolv.conf is a symlink to /var/run/NetworkManager/resolv.conf, and for some reason cat /etc/resolv.conf gives me error no such file or directory (maybe because it's empty?)

If I open it with vi and add nameserver x.x.x.x it works, but is cleared on reboot.

I tried to edit /etc/network/interfaces and add dns-nameservers x.x.x.x, changed /etc/dhcp/dhclient.conf and removed under request domain-name-servers, also edited prepend domain-name-servers x.x.x.x.

Resolvconf binary is not installed, NetworkManager.conf didn't have anything relevant. But everytime I restarted the machine, there was no domain server.

I'm not sure what the reason is but it seems to have to do with the fact that this is a VBox machine, started by GNS3 and because of that inside VBox setting, I have to leave it with no interface created. Apparently GNS3 creates a "UDP interface" on the fly when I start the machine, provided that I start it from GNS3.

So, to save me from searching endlessly, I just added echo nameserver x.x.x.x> /etc/resolv.conf to /etc/profile, problem solved (not solved, but worked around hehe). But it could be interesting to know what goes on with that scenario if anyone ran into it.


Solution:8

Just make entries in your ifcfg-ethX files like so

DNS1=192.168.X.X

DNS2=192.168.X.X

DOMAIN=yourdomain.com

then network manager will post pend those records to the resolv.conf file after you restart the services or restart your box.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »