Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

search puppetmaster.com
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)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1

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

11 Answers 11

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
    address 192.168.3.3
    netmask 255.255.255.0
    gateway 192.168.3.1
    dns-search example.com
    dns-nameservers 192.168.3.45 192.168.8.10

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
8  
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
    
I've removed the line. The other option would be to use tail instead of head. –  tgm4883 Oct 30 '12 at 11:44
1  
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
1  
@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
1  
@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

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-search google.com
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
2  
dhclient rules over any resolvconf settings so this should be the best answer. –  axlroden 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 8.8.8.8; 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:

  /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
2  
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

first

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

add this line

dns-nameservers yourdns youraltdns

example for google dns

dns-nameservers 8.8.8.8 8.8.4.4

second

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

third

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

this work on my ubuntu..

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

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 rn.yourcompany.com and you want to have it be search rn.yourcompany.com yourcompany.com intnet.yourcompany.com:

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:

DOMAIN="yourcompany.com intnet.yourcompany.com"

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

search rn.yourcompany.com yourcompany.com intnet.yourcompany.com
share|improve this answer
    
Not to rain on your parade, but this is Ask Ubuntu, and so Fedora is off-topic. –  Flimm Dec 3 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 8.8.8.8

root@hvnatvcc: ~ # cat /etc/resolvconf/resolv.conf.d/head 
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
share|improve this answer
2  
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

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 (127.0.0.1) 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 127.0.0.1) 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 127.0.0.1.

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

add on the last line eg:

nameserver 8.8.8.8

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

That configuration is declared in /etc/default/bind9

RESOLVCONF=no|yes

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

check this if you are still in trouble with your network configuration

http://youtu.be/oonDdIZk1LA

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.

http://manpages.ubuntu.com/manpages/lucid/man8/resolvconf.8.html

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

sudo resolvconf –disable-updates

after:

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.

http://manpages.ubuntu.com/manpages/lucid/man8/resolvconf.8.html

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

sudo resolvconf –disable-updates

despues:

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
3  
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 at 6:09

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.