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
containsnameserver 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:
The Desktop and Common Infrastructure sections contain a link to
I found another approach here that involves adding a line like the one below to
/etc/dhcp/dhclient.conf
:Likewise, I found a third approach here that involves adding lines to
/etc/network/interfaces
: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
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
Press Ctrl x and answer yes to saving the file. To finish up, regenerate /etc/resolv.conf so the changes are applied right now:
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.
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:
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 :)
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
orifup 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. Theresolvconf
utility only ever writes to the file/run/resolvconf/resolv.conf
.resolvconf
is useless. I'm on a Linux server and my IP address is static and my DNS servers are static. I do not needresolvconf
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 didchattr +i
(immutable) to/etc/resolv.conf
as a precaution.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 127.0.0.1;
(In fact, this line is already present ; all you need to do is un-comment it.)
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):It doesn't matter how often I run
sudo resolvconf -u
orsudo 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: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:
Just removing this file (and running
sudo resolvconf -u
afterwards) solved my dns troubles: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 runls /run/resolvconf/interfaces
to see what's there.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.