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

id=Auto Ethernet



  • 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/*. Aug 26, 2011 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, 2011 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, 2011 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, 2011 at 2:46
  • 1
    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, 2012 at 8:21

15 Answers 15


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

  • My network manager changes would be reverted on connecting to any VPN. This allowed me to keep in the resolver list irrespective of which network I connected to.
    – Steven P
    Feb 21, 2017 at 18:07

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

  • 1
    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). Aug 26, 2011 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, 2011 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. Aug 27, 2011 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. Nov 3, 2011 at 1:30

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.

  • 2
    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, 2013 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
  • 1
    this did not work for me. Restarting network manager still overwrites /etc/resolv.conf with the DHCP nameservers.
    – Tommy
    Dec 15, 2016 at 19:01
  • 1
    worked for me on a Debian 9 VM running inside of GCP. yay! thanks!
    – Randy L
    Aug 9, 2017 at 14:38
  • worked for me and learned a new skill / Linux feature
    – gcr
    Feb 6, 2022 at 2:44
  • worked for me in ubuntu 22.04
    – sam nikzad
    Mar 24, 2023 at 15:50

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

Add any entries to this file:


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?


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


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

  • Careful. I thought this was the most elegant solution for me, but it ended up bringing down the entire GCP node because networking couldn't start. I had to dismount the disk, mount to another node, remove the change, and remount.
    – ctrlbrk
    May 25, 2020 at 17:18

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

you can configure NetworkManager to stop resetting resolv.conf with

sudo sh -c 'echo "
" >> /etc/NetworkManager/NetworkManager.conf'
cat /etc/NetworkManager/NetworkManager.conf

Now manually change your /etc/resolv.conf and test its permanence with

sudo systemctl restart NetworkManager
# sudo service network-manager restart
cat /etc/resolv.conf

Source: https://askubuntu.com/a/623956/452398

  • Thank you, adding dns=none fixes the problem in proper way.
    – Tires
    Aug 26, 2019 at 16:36

Just make entries in your ifcfg-ethX files like so




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.



When there is # Generated by NetworkManager in /etc/resolv.conf

Edit Network Manager config:

sudo vim /etc/NetworkManager/NetworkManager.conf

in [main] section add rc-manager=unmanaged:



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: https://developer.gnome.org/NetworkManager/stable/NetworkManager.conf.html

Then edit your /etc/resolv.conf and restart Network Manager to see, if /etc/resolv.conf stays untouched:

sudo systemctl restart NetworkManager


sudo service network-manager restart


cat /etc/resolv.conf

If procedure failed and /etc/resolv.conf was overwritten during Network Manager restart try adding dns=none to [main] section in config as https://askubuntu.com/a/1150326/364772 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 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.conf

I hope this helps.


on my RaspberryPi

sudo nano /etc/dhcpd.conf

add to the end (or modify if already exists)

static domain_name_servers=

Ctrl + X + Y to save and exit. After reboot you're good to go


for me, I found out that it was tailscale

# resolv.conf(5) file generated by tailscale
# For more info, see https://tailscale.com/s/resolvconf-overwrite

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .