Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is /etc/resolv.conf useless in 12.04?

I see that DNS server info is stored in Network Manager 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?

share|improve this question
Smells like quirks to circumvent emphasized bad configuration. Really not too much or not enough detailed. – shellholic Mar 6 '11 at 21:19
@shellholic - If that's true, then why is there a standard feature in Ubuntu Server, but not Ubuntu Desktop, where one can auto-add nameservers and other entries into /etc/resolv.conf on boot? – Volomike Mar 7 '11 at 15:53
@shellholic - And in fact, why is there a commented-out way to do this already in /etc/dhcp3/dhclient.conf on the desktop? (Which is why I chose that answer.) – Volomike Mar 7 '11 at 15:55
@Volomike: perhaps for something else, this option is not to avoid that "every lookup has to go out to [your] slow ISP DNS lookup". The name resolution is configured in /etc/nsswitch.conf. If you configured your host in /etc/hosts and goes nevertheless to your ISP's DNS, it's a misconfiguration in hosts file, not the DNS config. You was circumventing it with a resolv.conf trick, now you try to replicate a bad behavior by adding a worst one. The feature you use on your server is in the package resolvconf (renamed openresolv in Natty). – shellholic Mar 7 '11 at 16:56
@Volomike: the utility of those feature is normally to be used for DNS proxying, DNS local caching,... I wanted to help, and didn't wanted to keep you in the error. – shellholic Mar 7 '11 at 17:08
show 3 more comments

12 Answers

up vote 41 down vote accepted

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

However, if /etc/resolv.conf contains 127.0.0.1, then adding entries to /etc/resolvconf/resolv.conf.d/tail won't really do anything useful. You should instead set the list of DNS servers statically in Network Manager which will then be configured in dnsmasq (that's running on 127.0.0.1).

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

share|improve this answer
@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. – Randall Cook May 8 '12 at 23:02
@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
What a bout adding entries to /etc/resolvconf/resolv.conf.d/head (as per your blogpost)? – sup Mar 12 at 16:15

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.

share|improve this answer
4  
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
1  
the third approach rocks! – coma Sep 11 '12 at 11:06
It sucks that internet is full on old info - this is so simple now :) – Mikko Ohtamaa Oct 5 '12 at 10:09
1  
@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. – Jeff Atwood Oct 17 '12 at 21:49
5  
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
show 1 more comment

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.

share|improve this answer

Below I will show you the best way that I have found since I run server edition and have no GUI tools!

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 like the example below:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
        address 192.168.1.2
        netmask 255.255.255.0
        network 192.168.0.0
        broadcast 192.168.1.255
        gateway 192.168.1.1
        dns-nameservers 75.75.75.75 75.75.76.76
        dns-search local

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

share|improve this answer
Thank you very much. – Saeed Zarinfam Dec 18 '12 at 5:54

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

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

share|improve this answer
You are so awesome! How on EARTH did you find that? – Volomike Mar 7 '11 at 15:54
There was a question here somewhere that clued me in on the existence of the /etc/dhcp3 structure, and then I used a fix very similar to this to address an issue with AT&T's DNS timing out. – belacqua Mar 8 '11 at 0:04
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.) – Christian Skjødt Aug 31 '11 at 16:01

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

share|improve this answer

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.

share|improve this answer
Thank you Frank, I did that. – Fabio May 4 '12 at 14:34

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.

share|improve this answer
instead of adding entries, fix the system the is broken and giving you the info you actually want. +1. – nelaar Feb 5 at 12:30

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.

share|improve this answer
1  
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

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.

share|improve this answer

Mine running Ubuntu Server 12.04, I have made following changes and reboot the server (typically can be done by only bring down the network interface, i.e. ifdown eth0 or ifup eth0).

/etc/resolvconf/resolv.conf.d/base

Added following entries:

nameserver 8.8.8.8
nameserver 8.8.4.4

Hope above helps!

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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