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 localdomainI 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 dhclientAnd 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 dhcpNo 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 7 14 Answers
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.)
1(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 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 wAudit 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.
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.
1Open up a terminal and type
sudo chattr +i /etc/resolv.confthe +i takes care that the file wont be reseted on a boot even by root.
To undo the above
sudo chattr -i /etc/resolv.confFor more
man chattr 3 Another option that I've had some luck with involves using resolvconf.
Add any entries to this file:
/etc/resolvconf/resolv.conf.d/baseAnd 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?
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.
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.
If you have the file /etc/NetworkManager/NetworkManager.conf
cat /etc/NetworkManager/NetworkManager.confyou can configure NetworkManager to stop resetting resolv.conf with
sudo sh -c 'echo "
[main]
dns=none
" >> /etc/NetworkManager/NetworkManager.conf'
cat /etc/NetworkManager/NetworkManager.confNow manually change your /etc/resolv.conf and test its permanence with
sudo systemctl restart NetworkManager
# sudo service network-manager restart
cat /etc/resolv.confSource:
1Just 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.
Just in case someone falls in the same case:
I Forgot I set dhcp on an interface inside the file /etc/network/interfaces
Networkmanager will modify /etc/resolv.conf from the dhcp answer he gets.
hth
When there is # Generated by NetworkManager in /etc/resolv.conf
Edit Network Manager config:
sudo vim /etc/NetworkManager/NetworkManager.confin [main] section add rc-manager=unmanaged:
[main]
rc-manager=unmanagedWhy?
rc-manager- Set the resolv.conf management mode. The default value depends on NetworkManager build options, and this version of NetworkManager was build with a default of "symlink".(...)
unmanaged: don't touch/etc/resolv.conf.
Config reference for more info:
Then edit your /etc/resolv.conf and restart Network Manager to see, if /etc/resolv.conf stays untouched:
sudo systemctl restart NetworkManageror
sudo service network-manager restartthan:
cat /etc/resolv.confIf procedure failed and /etc/resolv.conf was overwritten during Network Manager restart try adding dns=none to [main] section in config as said
for me the file that was re-setting was sudo nano /etc/systemd/resolved.conf
and here /run/systemd/resolve/resolv.conf
i changed it to 8.8.8.8 based on google search.
It's very simple. /etc/resolv.conf is managed by systemd, so you have to adapt the file that controls this file:
sudo nano /etc/systemd/resolv.confI hope this helps.
on my RaspberryPi
sudo nano /etc/dhcpd.confadd to the end (or modify if already exists)
static domain_name_servers=8.8.4.4 8.8.8.8Ctrl + X + Y to save and exit. After reboot you're good to go