I have set up multiple virtual machines with libvirt and kvm on Ubuntu server 20.04, which work just as expected. The only thing I cannot figure out at this point is how to make their hostnames resolvable between the guests and from the host, at the moment I can only access them via their ip addresses which I can get from virsh net-dhcp-leases default.

I'd like to access the virtual machines by their hostname or similar both from the host and from within the virtual machines, as relying on these ip addresses is a bit inconvenient, but am not sure how to achieve this. I have tried following articles such as this. If a host is named test I want it to be reachable by both test and test.example.com, while external.example.com is not resolved to an internal address, but an external one possibly somewhere else, which I think could be a problem with the solution in the article above. Would this be best achieved by adding entries manually in the hosts /etc/hosts or by something similar in the article above? I have tried adding entries to the /etc/hosts/ file but the entries have only worked on the host machine, but I assume that it is because I haven't properly set up dnsmasq or something similar.

Any help will be appreciated, since I am very much a confused beginner and it is quite overwhelming.


1 Answer 1


Libvirt provides a nss module which you can configure on the host, which uses the net-dhcp-leases information to provide host resolution https://libvirt.org/nss.html

  • this looks promising! at the moment i have solved it using dnsmasq via networkmanager, where i manually input entries for each vm, which isn't a big deal since i have very few guests, but is more to maintain Nov 23, 2020 at 13:26
  • works pretty much as i want it, only thing that i'd like to get working is accessing the guests both from test and test.example.com given that the hostname is test Nov 23, 2020 at 13:36
  • also ran into an issue where docker containers, even in host network mode dont seem to recognize the hostnames. possibly docker / docker network not using nsswitch.conf? Nov 23, 2020 at 14:04

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.