Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have finally migrated to 12.04 from 7.10. I have one last part to complete but I am stumped. I am using Puppet on each server, and in the past I have included a nameserver address and a search domain name for the puppetmaster in resolv.conf.

nameserver 192.168.1.XXX

In 12.04 resolv.conf gets overwritten when rebooted. I cannot use a static IP for these, so using the /etc/network/interfaces to help me out is a nill point.

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

Is there a way to get resolvconf to handle this either in the head, tail or base? If there is, are there any examples I can use to tweak on my server.

Any help is much appreciated.

share|improve this question

14 Answers 14

It's probably better to have your DNS server be able to resolve 'puppet' to the right address, and either to have your DHCP server hand out the DNS nameserver address and search list or else (if you have static IP addresses) to have something like the following in /etc/network/interfaces.

iface eth0 inet static

But if you do want to do it via the resolvconf configuration files you will want to edit /etc/resolvconf/resolv.conf.d/base. In that file, put in your info as you would in resolv.conf.

nameserver 192.168.1.XXX

Then tell resolvconf to regenerate resolv.conf.

sudo resolvconf -u
share|improve this answer
Although this answer has votes, and the first part is more or less correct, the second part of the answer is incorrect. (1) Do not put a "search" line in /etc/resolvconf/resolv.conf.d/head. If you put a "search" line there, this line will be ignored if resolvconf includes a "search" line in the dynamic part of the resolv.conf file. The glibc resolver ignores all but the last "search" or "domain" line. See resolv.conf(5). (2) If the resolvconf configuration is changed you should not restart the resolvconf job but just run an update, "resolvconf -u". – jdthood Oct 27 '12 at 18:46
base, head or tail (as of 12.04) are all being rewritten just like resolv.conf, so I can confirm that @jdthood comment is true. So, complete answer would say - do not edit any of resolv.conf files, and just run: sudo /etc/init.d/networking restart As a matter of fact, that will write interface changes to resolv.conf. – tishma Nov 1 '12 at 11:10
@tishma: Hi. First, to prevent any misunderstanding: nothing writes to the base, head or tail files. Nothing writes to any files in /etc/resolvconf/resolv.conf.d/ at run time. These files are read by resolvconf which assembles their content into the file that it writes --- /run/resolvconf/resolv.conf --- to which the symlink /etc/resolv.conf points. Second, concerning what to do after dns-* options in /etc/network/interfaces are changed. Do not run "/etc/init.d/networking restart"; that is now deprecated. Instead ifdown the interface in question and ifup it again. – jdthood Nov 1 '12 at 13:18
@tishma, that isn't what jdthood said. jdthood said that the last search and domain lines are the only ones used. – tgm4883 Nov 1 '12 at 14:38
In 14.04 this answer did nothing for me. – Jay Sullivan Jun 30 '14 at 0:55

I think the answer is check your /etc/dhcp/dhclient.conf

don't request dns-nameservers from your dhcp client.

Then update your /etc/network/interfaces

auto eth0
iface eth0 inet dhcp
dns-nameservers dnsserverip

Then your resolv.conf will get auto configured the way you want it.

Add to the dns-search and then run a /etc/init.d/networking restart (even though its been deprecated it works).

share|improve this answer
dhclient rules over any resolvconf settings so this should be the best answer. – Alex R Mar 4 '13 at 9:35
/etc/init.d/networking restart did not work on my machine, but sudo ifdown -a and then sudo ifup -a did. (Also, it took me a bit to realize I had to replace dnsserverip with something like; I feel a bit silly.) – Jason Gross Dec 9 '13 at 5:21

Please look at resolvconf's man page. You can force inclusion of certain DNS settings by creating e.g. /etc/resolvconf/resolv.conf.d/base:

          File containing basic resolver information.  The lines  in  this
          file  are  included in the resolver configuration file even when
          no interfaces are configured.

There are other special files (head and tail), these may help you achieve what you want.

share|improve this answer
You can add lines to /etc/resolvconf/resolv.conf.d/base, but because every nameserver is accessible via an interface and is accessible only when that interface is up, it is best to associate the nameserver information with that interface. If the interface is configured with ifup, this means: put the info on "dns-search" and "dns-nameservers" lines in /etc/network/interfaces stanzas. If the interface is configured via DHCP then this means: configure the DHCP server to supply search names and nameserver addresses to clients. Etc. Use the "base" file only as a temporary hack or as a last resort. – jdthood Oct 27 '12 at 18:56

it was caused by dhcp configuration when you first installing ubuntu just using this 3 step to handle this auto configuration


edit your interface configuration.. /etc/network/interface

add this line

dns-nameservers yourdns youraltdns

example for google dns



edit your dhcpconfiguration.. /etc/dhcp/dhclient.conf and mark the syntax as comment using "#" on every line or simply remove every request name-server


restart your networking by using this command /etc/init.d/networking restart

this work on my ubuntu..

share|improve this answer
/etc/init.d/networking restart did not work on my machine, but sudo ifdown -a and then sudo ifup -a did. – Jason Gross Dec 9 '13 at 5:22
This is simple and it works even though it is a bit hacky! Problem with things like ubuntu is having 1000 ways to do one thing! – Willa O Ng'wana Jul 18 at 12:52

For me, the above answers were inadequate for the following reasons:

  • I'm not using resolvconf, just plain /etc/resolv.conf.
  • Using chattr +i to lock down resolv.conf seems too hacky. I need Puppet to be free to make changes when necessary.
  • AFAIK, editing /etc/network/interfaces doesn't prevent resolv.conf from being overwritten; it simply specifies the name servers that should be written. For me, specifying the name servers wasn't the point. I'm trying to set options timeout:1 and options attempts:1 in my resolv.conf file.

The best solution I found overrides the default behavior of dhclient using its documented hooks.

Create a new file at /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate with the following contents:

make_resolv_conf() {

Then make the file executable:

chmod +x /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate

Now when dhclient runs -- either on reboot or when you manually run sudo ifdown -a ; sudo ifup -a -- it loads this script nodnsupdate. This script overrides an internal function called make_resolv_conf() that would normally overwrite resolv.conf and instead does nothing.

This worked for me on Ubuntu 12.04.

share|improve this answer
Works fine on Debian 8. Elegant solution! – Artur Bodera Oct 15 '15 at 7:19
just for completeness: manpage dhclient-script holds the information about the DHCP client network configuration script mentioned an the answer above. – hecke Feb 5 at 19:36

This may just be some weird quirk in my machine, but someone else might have the same corner case.

I tried numerous ways to get my ISP nameservers included in /etc/resolv.conf with no success:

  • I included them in /etc/network/interfaces and restarted networking. They didn't show up in /etc/resolv.conf.

  • I put them in /etc/resolv.conf explicitly, but of course they got overwritten. They did show up in /run/resolvconf/interface/eth0.inet, but never made it to /etc/resolv.conf.

  • I tried configuring resolvconf for dynamic updates. No change.

Finally I read somewhere that if the local machine ( shows up in /etc/resolv.conf any other nameservers are not included.

In desperation I edited /run/resolvconf/interface/lo.named, deleted the only line in it (nameserver and restarted: ifdown eth0 && ifup eth0.

/etc/resolv.conf then included my ISP nameservers for the first time! I ran service network-manager restart to see if it was stable and /etc/resolv.conf still includes my ISP nameservers. Rebooted just to make sure and it's still there but /run/resolvconf/interface/lo.named got reset to: nameserver

Curiously restarting networking still works: /etc/resolv.conf still contains my ISP nameservers. I can't explain this (can someone?) but this might help someone stuck in the same spot.

share|improve this answer
This is probably caused by dnsmasq. You can simply remove it using apt-get remove dnsmasq or update config in /etc/dnsmasq.conf. – Tombart Jan 8 at 22:44

The other solutions did not work for me on my Fedora 20 system. My particular problem was that the "search" line in /etc/resolv.conf was being overwritten. Here is what fixed it. (This assumes that NetworkManager is producing the line search and you want to have it be search

1.Use the "ifconfig" command to find out what interface is of interest:

$ ifconfig

em2:  <this was the one which was connected>

2.Become root and change to the system configuration network devices directory:

$ sudo su -[sudo] 
password for youruser:
# cd /etc/sysconfig/networking/devices`
  1. Use your favorite available editor to add a Domain line with the additional domains to search:


Save, logout, and log back in. NetworkManager should now have the line in \etc\resolve.conf:

share|improve this answer
Not to rain on your parade, but this is Ask Ubuntu, and so Fedora is off-topic. – Flimm Dec 3 '14 at 0:05

add your nameserver to file /etc/resolvconf/resolv.conf.d/head. The file contains message that you had received:

that file should looks like this after adding

root@hvnatvcc: ~ # cat /etc/resolvconf/resolv.conf.d/head 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
share|improve this answer
Adding lines to /etc/resolvconf/resolv.conf.d/head is a poor solution, even worse than adding lines to /etc/resolvconf/resolv.conf.d/base. The correct solution for interfaces configured using ifup is to add "dns-search" and "dns-nameservers" lines to stanzas in /etc/network/interfaces. See also my comments on the other answers. – jdthood Oct 27 '12 at 19:01

If you are using DHCP, edit /etc/dhcp/dhclient.conf to add additional DNS servers:

prepend domain-name-servers,;

The DHCP client overwrites the dns-nameservers in etc/network/interfaces and I think in /etc/resolvconf/resolv.conf.d/base too.

This worked for me in Ubuntu server 14.04.3.

See the Debian NetworkConfiguration Wiki for details.

share|improve this answer

Add entries in /etc/resolvconf/resolv.conf.d/head

sudo echo "search" >> /etc/resolvconf/resolv.conf.d/head 
sudo echo "nameserver 192.168.1.XXX" >> /etc/resolvconf/resolv.conf.d/head

and run following command

sudo resolvconf -u
share|improve this answer

add on the last line eg:


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.

To undo the above

sudo chattr -i /etc/resolv.conf

For more

man chattr
share|improve this answer

Just put a

dns-search && dns-nameservers (sample:

command on your /etc/network/interfaces configuration. then restart your network.

it should work.

share|improve this answer

That configuration is declared in /etc/default/bind9


no = don't apply the condition in the init.d bind9

yes, or other value = override resolv.conf

This problem accures when you install bind9 and don't care about check all confs.

share|improve this answer

English translation:

My solved. "only 12.4"

I noticed that if you add the dns-nameserver in interfaces that do not take the name resolution server Thanks to the help found here have solved the problem.

To make resolv.conf not change when we edit manually do this in the terminal:

sudo resolvconf –disable-updates


sudo resolvconf -a eth0 # or your network Interfas

then manually edit /run/resolvconf/resolv.conf

adding a maximum of two DNS servers. thanks P.S. not forget to restart:

sudo /etc/init.d/networking restart

Original text:

solo ubuntu 12.4

Mi solucion.

He visto que si agregas los dns-nameserver en interfaces esta no toma los server de resolucion de nombres

Gracias a la ayuda encontrada en esta pagina he resuelto el problema.

Para hacer que resolv.conf no cambie cuando la editamos manualmente hacemos esto en la terminal:

sudo resolvconf –disable-updates


sudo resolvconf -a eth0 # o tu interfas de red

luego editamos manualmente /run/resolvconf/resolv.conf

agregando un maximo de 2 DNS servers. saludos P.D. no olvidar reiniciar:

sudo /etc/init.d/networking restart
share|improve this answer
This is very much not the right way to solve the problem. – jdthood Oct 27 '12 at 18:57
@jdthood as someone browsing this can you elaborate WHY this is not the right way? It seems logical to me, but I do not know anything about this. – ErikPerik Mar 25 '14 at 6:09

Your Answer


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.