Is /etc/resolv.conf useless in Ubuntu 12.04 LTS (Precise Pangolin)?

I see that the DNS server information is stored in NetworkManager now. The nmcli command line tool can list that for you.

If I want to add one more DNS server, will adding it to /etc/resolv.conf by using the resolvconf package help?

  • 2
    I think the command mentioned above should be nm-tool, not nmcli. Jul 19 '13 at 17:40

20 Answers 20


If /etc/resolv.conf contains nameserver then adding entries to /etc/resolvconf/resolv.conf.d/tail won't really do anything useful.

If you are using NetworkManager then you should instead statically add nameserver addresses via network indicator: Edit Connections... | Edit... | IPv4 Settings | Additional DNS servers.

If you really want to add more entries to /etc/resolv.conf, create a /etc/resolvconf/resolv.conf.d/tail and add them there.

As with every Ubuntu release, it's recommended to read the Ubuntu Release Notes, available here:

The Desktop and Common Infrastructure sections contain a link to

  • 1
    @stgraber, please comment on the alternative approach I found and posted below. How does it compare with adding an /etc/resolvconf/resolv.conf.d/tail file or using Network Manager? Thanks. May 8 '12 at 23:02
  • 3
    @stgraber What do you recommend for Ubuntu Server? I've noticed from your blog and comments that Network-Manger seems to be the best way to manage this, but doing an install of network-manager on my system would install a whole bunch of things I don't need (i.e. GUI stuff).
    – Avery Chan
    Jun 22 '12 at 3:17
  • 1
    What a bout adding entries to /etc/resolvconf/resolv.conf.d/head (as per your blogpost)?
    – sup
    Mar 12 '13 at 16:15
  • 3
    @AveryChan, use the "third approach" suggested by @randallcook—just add dns-nameservers to your eth0 section in /etc/network/interfaces.
    – mrm
    Aug 26 '13 at 5:15
  • 1
    /etc/resolvconf/update.d/libc on Ubuntu 14.04.1 server : # Set TRUNCATE_NAMESERVER_LIST_AFTER_LOOPBACK_ADDRESS=no # to allow additional nameserver addresses to be listed in # resolv.conf after an initial loopback address 127.* or ::1. (set it in /etc/default/resolvconf, as line 23 & 24 of /etc/resolvconf/update.d/libc show. Feb 14 '15 at 4:07

I found another approach here that involves adding a line like the one below to /etc/dhcp/dhclient.conf:

prepend domain-name-servers x.x.x.x, y.y.y.y;

Likewise, I found a third approach here that involves adding lines to /etc/network/interfaces:

auto eth0
iface eth0 inet static
    . . .

Update: Here is the official documentation for the third approach.

  • 18
    I voted for this because the third approach is by far the simplest way to do this.
    – Billy Moon
    Jul 17 '12 at 9:27
  • 2
    @billy I could not get the third method to work at all.. only the first one listed here, editing the dclient.conf, worked for me. Oct 17 '12 at 21:49
  • 9
    Note: Editing dhclient.conf only has any effect if dhclient is used (and it is used by both ifup and NetworkManager!) Editing /etc/network/interfaces only has any effect if ifup is used. Configuring NetworkManager connections using the NetworkManager connection editor only has any effect if NetworkManager is used.
    – jdthood
    Oct 29 '12 at 14:26
  • 2
    If I am not mistaken the third approach adds another nameserver AFTER the ones returned by DHCP. If you want it to come first then one of the other options is more appropriate. I used /etc/resolvconf/resolv.conf.d/head (after overcoming the misleading "DO NOT EDIT" comment in there :) )
    – starfry
    Sep 15 '14 at 10:46
  • 1
    @Mr.Hyde, those aren't command line commands, they are lines to add to /etc/network/interfaces. Jul 7 '15 at 5:49

It sounds like you are talking about the resolvconf package.

Install the resolvconf package.


cd /etc/resolvconf/resolv.conf.d
sudo cp -p head head.orig  #backup copy, always do this
sudo nano head

The top of the file is a scary warning. The file /etc/resolv.conf is autogenerated from the contents of this file; the warning is there so it will get put in /etc/resolv.conf when /etc/resolv.conf is generated. To the end of the file, add

nameserver <ip_of_nameserver>

Press Ctrl x and answer yes to saving the file. To finish up, regenerate /etc/resolv.conf so the changes are applied right now:

sudo resolvconf -u

Then check the contents of /etc/resolv.conf to see the line you added is now there. Further, it will still be there the next time your machine boots or your network service is restarted, whichever comes first.

  • 1
    The information about the file warning is just what I needed. I was under the impression that I shouldn't edit the file! Thanks!
    – Xunnamius
    Oct 22 '17 at 5:51
  • This is the best answer for me!
    – Siwei
    Nov 1 '18 at 11:23

Below I will show you the best way that I have found since I run Ubuntu Server edition and use ifup rather than NetworkManager.

Actually for me they made this easier :) by putting it all into the /etc/network/interfaces file. The same configurations that you would have written to resolv.conf can now be in the same file as your network adapter configurations as in the example below:

# The loopback network interface
auto lo
iface lo inet loopback

# The Primary Network Interface
auto eth0
iface eth0 inet static
        dns-search local
        wildcard mask
        cidr prefix size /24
        cidr notation
        first host
        last host
        mac address J7:836:737:727:gsgd837:g645

I hope this helps out and makes it easier as it does for me, now we can create static IP addresses and add in nameservers and dns domain all in one file :)

  • 1
    Thank you. This has become my favorite method as well. An off-topic note: it's not necessary to specify the 'network' and 'broadcast' addresses since they're automatically calculated from the 'address' and the 'netmask'. All you really need are 'address', 'netmask' and 'gateway'. Feb 21 '14 at 10:16
  • This is the cleanest answer. Just make sure to spell the dns-* keywords correctly. Misspelled "dns-nameservers" was my actual problem. Apr 13 '18 at 21:28

Mine is running Ubuntu Server 12.04. I have made the following changes and rebooted the server (typically this can be done by only bringing down the network interface, that is, ifdown eth0 or ifup eth0).

In file /etc/resolvconf/resolv.conf.d/base I added the following entries:


I hope the above helps!


You can use NetworkManager as stated in Frank's answer, but if you would rather manually edit /etc/resolv.conf, you can do so by deleting it (it's actually a symlink) and then creating a new plain file with the content you want. The resolvconf utility only ever writes to the file /run/resolvconf/resolv.conf.


Note: This answer was for a rather different, pre-merge version of the Question, with a focus only on pre-pending a desired name-server.

This works pre-12.04:

Edit /etc/dhcp3/dhclient.conf and add :
prepend domain-name-servers;

(In fact, this line is already present ; all you need to do is un-comment it.)

  • Does this work if you don't have any addresses assigned by DHCP?
    – Azendale
    Jun 30 '11 at 23:34
  • If you want to learn more about the dhclient configuration you can do a man dhclient.conf to access the dhclient man page. (This is not a response to Azendale's question.) Aug 31 '11 at 16:01
  • This answer is completely wrong. First of all, the question submitter wants to add the address of an external namserver, not the address The interface configurer for an external interface is not the place to add an address for an internal nameserver. Second, the file is at /etc/dhcp, not at /etc/dhcp3. Third, since Ubuntu 12.04 such things are configured using resolvconf.
    – jdthood
    Oct 3 '13 at 8:29
  • 1
    First of all -- the original question was dramatically changed by moderator merging, so my answer of course looks strange. The dhcp3 file was the location when I answered this in 2011, and even if it's not ideal, it worked. I've used this solution on multiple machines. Obviously, you would change the loopback address to the one you want to prepend. I assume most people know what a loopback is, even if they haven't read RFC6890.
    – belacqua
    Oct 4 '13 at 15:11
  • @jdthood Why not add your own answer? Personally, I was not familiar with the bsd-ish resolvconf way of doing things. I preferred the direct /etc/resolv.conf approach, and I'm not sure what the advantage of the new Rube Goldberg system is. (Likewise with /etc/motd).
    – belacqua
    Oct 4 '13 at 15:46

resolvconf is useless. I'm on a Linux server and my IP address is static and my DNS servers are static. I do not need resolvconf or NetworkManager.

Keeping it simple is my policy when working on a server. The less complexity, the easier it'll be to manage/fix when things break.

So I did aptitude purge resolvconf and manually made sure /etc/resolv.conf isn't a symlink and just created a static file. Just in case a program tries to change the file, I did chattr +i (immutable) to /etc/resolv.conf as a precaution.

  • 4
    As resolvconf is part of the base system, by deleting it you are asking for trouble in the future, at upgrade time.
    – jdthood
    Oct 29 '12 at 14:30
  • 4
    I agree with both the comment and the answer: consider how many problems this has caused, and how many support hours have gone into fixing this "problem", and how many IT staff have spent time looking for answers. Simple is best - I don't need my servers to be changing the DNS to something I don't want.
    – Mei
    Jul 30 '14 at 16:40

Most of the above assumes you have a pristine system, but reality is often such that you have been installing different dhcp clients, disabled the network manager in certain previous version of Ubuntu, etc. It might be worthwhile to know the following. I've been using dnsmasq for a while, but deinstalled it. Currently my system had the following contents of /etc/resolv.conf (which is a symbolic link to /run/resolvconf/resolv.conf on my system):

cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)

It doesn't matter how often I run sudo resolvconf -u or sudo dpkg-reconfigure resolvconf, it didn't update the nameserver to the ones I set in the NetworkManager. The information resolvconf does use from the NetworkManager was present:

cat /run/resolvconf/interface/NetworkManager  

However, it turns out to be the case that if there are multiple files in this directory, this file might not be used at all. The culprit was a file not removed with the deinstallation of dnsmasq:

cat /run/resolvconf/interface/lo.dnsmasq                        

Just removing this file (and running sudo resolvconf -u afterwards) solved my dns troubles:

cat /etc/resolv.conf                        
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)

I hope this helps others with debugging (the complex interactions between all these different network tools) as well. If you use resolvconf make sure to run ls /run/resolvconf/interfaces to see what's there.

  • 1
    Thank you, this was very helpful. I tried the higher voted answers first and none seemed do do the trick. I didn't have any additional files in the /run/resolvconf/interface/ dir, but my NetworkManager file needed some love. Your answer helped resolve this issue for me.
    – mason81
    Jul 2 '15 at 14:40

I just deleted a link in /etc/resolv.conf and created a regulary file with the nameservers' adresses. It works, and I don't see any reasons to use that rather strange construction that the Ubuntu developers have created.

  • 1
    Yes, I am not a fan of this kind of change which affects servers, adds complexity and opacity. This is core behavior that shouldn't change from release to release.
    – belacqua
    Oct 4 '13 at 15:32
  • This answer is 5 years old, and IMHO is still the best of all those listed. It is simple, quick and effective. Is there any downside? Mar 9 '19 at 4:02

You can edit the connection "AUTO ETH0" or whatever the name is that you use to connect in NM. You can do this by right-clicking on NM and selecting "Edit Connections...". On the IPv4 tab you can select "Automatic (DHCP) addresses only" as the "Method" and NM will allow you to set the nameserver address(es) manually even addresses are delivered over DHCP.


Adding my bit to the already long list, here's another way (tested on 12.04):

Edit /run/resolvconf/interface/NetworkManager to fit your needs. Here's an example:

search foobar.com example.com

Then, as stated for most of the other examples, do a sudo resolvconf -u. Now you will find your resolv.conf looking like this:

search foobar.com example.com

I still don't like the way it's implemented now (seems Ubuntu needs a service for every foo it makes), and would prefer a plain resolv.conf for sure. But this approach seems to be the best compromise for me so far. The added "localhost-NS" shouldn't hurt too much.


I fixed this by changing the order of sources. I moved the dns source before mdns in /etc/nsswitch.conf:

hosts: files dns mdns4_minimal [NOTFOUND=return] mdns4

You can keep your settings and still use the local caching server this way.

  • instead of adding entries, fix the system the is broken and giving you the info you actually want. +1.
    – nelaaro
    Feb 5 '13 at 12:30

How about:

sudo dpkg-reconfigure resolvconf

Before that, use Network Manager to change DNS adress and change Method to

Automatic (DHPC) adresses only

Then run the command above and reboot. That did the solution for me.

vi /etc/network/interfaces

This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The primary network interface
allow-hotplug eth0

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#auto eth0         <<----- change this comment with the #
iface eth0 inet dhcp

This is a very popular question, with a collection of standard possible answers, all of which, IMO, are pretty hacky. I for one have always had problems getting Ubuntu to respect the DNS settings I set up in NetworkManager -- in particular setting static DNS servers with "Automatic (DHCP) addresses only" -- and today I finally figured out what was ACTUALLY WRONG.

The problem is in the interaction between resolvconf and NetworkManager. resolvconf has this file called /etc/resolvconf/interface-order. At least on my systems, NetworkManager isn't in this file at all (except that it's covered by the * wild card at the end). So what happens is, dhclient's most recent report to resolvconf takes precedence over anything NetworkManager has to say.

Thus, at least in my case, the actual answer was to add


at or near the top of /etc/resolvconf/interface-order.

(Yes, I know many people just say "uninstall resolvconf", which seems like a bad idea in and of itself, to me. But more than that, at least wily and xenial consider resolvconf a vital part of the system [i.e., ubuntu-minimal depends on it], so it would be difficult to keep your system in a consistent, updated state without resolvconf.)

Upon request I can provide more detail about how I figured this out. (EDIT: apparently I didn't do so when it was requested, sorry. At this point I don't remember much more detail than what I say next:) In a nutshell, I replaced the resolvconf executable with a shell wrapper around it which dumped its arguments, input, output and stderr to files; and added set -x to resolvconf's update scripts.

(EDIT: I can say that what I mean by the first part is that I used sudo to move the actual resolvconf executable, which could be found using the which command or the type command. Then create a shell script that ultimately just executes the moved resolvconf, but also echos the arguments to some file, and uses shell redirection to send stdin, stdout, and stderr to various other files. I don't recall where "resolvconf's update scripts" are and can't currently easily check. I think many Linux geeks can figure out what I mean; perhaps some good samaritan will provide even more detail in a comment.)

  • Please "provide more detail about how you figured this out" May 31 '16 at 19:49

Another way is to define docker specific dns servers at:


If you don't have such a file, just create it:

    "dns": ["", ""]

Source, also see this.


To change DNS, follow instructions in: https://developers.google.com/speed/public-dns/docs/using

  1. Go to Network

  2. For the connection you want to configure the DNS, click on the gear.

  3. Click the IPv4 or IPv6 Settings tab.

  4. If the selected method is "Automatic", select "Automatic (DHCP) addresses only" instead. If the method is set to something else, do not change it.

  5. In the DNS servers field, enter the DNS IP addresses, separated by a comma

EDIT: As this seems to not be working well in newer ubuntu, I would:

sudo systemctl disable systemd-resolved.service
sudo gedit /etc/resolvconf/resolv.conf.d/head 
# add

sudo resolvconf --enable-updates
sudo resolvconf -u

Source: https://pchelp.ricmedia.com/set-custom-dns-servers-linux-network-manager-resolv-conf/

  1. Add temporary DNS. Edit /etc/resolv.conf.

  2. Install or update resolvconf.

    sudo apt-get install -y resolvconf
  3. Add your nameserver into /etc/resolvconf/resolv.conf.d/tail

  4. Reboot your machine: reboot

  • Who are you? I am used to starting from zero.
    – xiaoliuzi
    Nov 18 '19 at 11:28

In my case, the real problem was that the DHCP server was providing an IP address but failing to provide a DNS server. Solved by restarting the DHCP server (and then reconnecting from NetworkManager).

I was able to diagnose it by checking the DHCP details available from nmcli:

to show current connections, one line each:
$ nmcli c

to show more detail about connections and DNS:
$ nmcli

to show the most detail about a specific connection:
$ nmcli c s enp0s5

to filter useful lines about DHCP assignment and DNS:
$ nmcli c s enp0s5 | grep -i "dhcp\|domain\|dns\|ip"

When DNS from DHCP is working correctly, the output includes both of these critical lines:

DHCP4.OPTION[9]:          requested_domain_name_servers = 1
IP4.DNS[1]:        (or some other value)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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