3

I have a guest machine running ubuntu 14.04 on an Ubuntu 14.04 host running KVM/QEMU.

Everything works fine except for one thing. Given my guest's hostname is virtual-machine-1, I would like to be able to find it from the host machine.

In especially, if I use host virtual-machine-1 on the host machine, I would like it to return the guest's IP address.

The documentation on KVM/Networking states:

If on your host machine you add 192.168.122.1 (the default IP of your host in libvirt) as your first nameserver in /etc/resolv.conf [... blabla it should work]

And this indeed works. But the resolv.conf file is regularly overwritten and the extra added line gets lost.

Which leads me to my question: What is the appropriate way to reflect this change?

Here's what I've tried to no avail:

  • adding it to /etc/resolvconf/resolv.conf.d/base
  • adding the dns-nameserver to my /etc/network/interfaces file

It seems like the nameserver 192.168.122.1 needs to precede any other (including 127.0.1.1). The documentation states that this is normal and that dnsmasq will handle it correctly. I just don't know how to configure this in a lasting manner.

  • There's a /etc/resolvconf/resolv.conf.d/head file as well. Did you try adding to that? – muru Aug 16 '14 at 14:53
  • It reads DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN so I haven't tried. – D.Mill Aug 16 '14 at 15:05
  • If you notice, that's the exact same header that is shown in /etc/resolv.conf generated by resolvconf, because it uses that file as the header. Neither base nor head are ever overwritten, but stuff in head always appears before base (there also maybe a tail). :) – muru Aug 16 '14 at 15:07
  • @muru Duh I feel a little dumb. This obviously works and I don't think there are any counter indications. If you wish you can answer the question and I'll select it as the correct one. – D.Mill Aug 16 '14 at 17:09
2

resolvconf generates /etc/resolv.conf using files from /etc/resolvconf/resolvconf.d/, which usually contains a head, a base and maybe a tail. From the manpage:

   The dynamically generated resolver  configuration  file  always  starts
   with  the  contents of /etc/resolvconf/resolv.conf.d/head and ends with
   the contents of /etc/resolvconf/resolv.conf.d/tail.  Between  head  and
   tail  the  libc  script inserts dynamic nameserver information compiled
   from, first, information provided for  configured  interfaces;  second,
   static  information  from /etc/resolvconf/resolv.conf.d/base.

As you may have observed, the generated /etc/resolv.conf has a header warning that the contents are generated and the file should not be edited manually. This header is stored in /etc/resolvconf/resolvconf.d/head, so don't be confused by the presence of that warning in head. Files in /etc/resolvconf/resolvconf.d are not generated, and are meant for manualy editing if needed. So if any entries absolutely have to appear at the top of resolv.conf, add them to head. If the entries absolutely have to appear at the end (for example, the last search entry is always used), add them in tail.

  • Note for readers: if you are on a Debian-based distro, you may find that you do not have an /etc/resolvconf/resolvconf.d/ directory, or that running man resolvconf yields No manual entry for resolvconf. Chances are, your distro will allow you to easily fix this by running apt install resolvconf (or, for the old-fashioned, apt-get install resolvconf). – sampablokuper Dec 12 '17 at 21:41

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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