How do I add a DNS server via resolv.conf?

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?


If /etc/resolv.conf contains nameserver 127.0.0.1 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:

  • https://wiki.ubuntu.com/PrecisePangolin/ReleaseNotes/UbuntuDesktop

The Desktop and Common Infrastructure sections contain a link to

  • http://www.stgraber.org/2012/02/24/dns-in-ubuntu-12-04/ covering the changes to the DNS infrastructure in 12.04.

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
    . . .
    dns-nameservers 8.8.8.8 8.8.4.4

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


It sounds like you are talking about the resolvconf package.

Install the resolvconf package.

Run

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.