tl;dr: How can I get DNS on my machine to look up virtual machines I create in virsh?

I have virsh installed via the regular packaging on Ubuntu 18.04 (bionic). This results in two name servers - a dnsmasq instance running on that is for virsh instances and a /lib/systemd/systemd-resolved instance running on

The latter does not talk to the former. I'd like to fix that, but I'm not quite sure where to start.

If I make a virtual machine with virsh it uses DHCP to get it's IP address from that dnsmasq instance. The host sends it's name (vippy) and dnsmasq records it. If I type host vippy works, but dnsmasq is not configured to assume a domain name. So I want to make host vippy.hosts.virsh work.

The next issue is having systemd-resolved route all requests to .hosts.virsh to


Like most systemd replacements for important services (ntp, dns, cron, etc) systemd-resolved is a half-arsed implementation that is only suitable for desktop machines that happen to be a lot like Lennart Poettering's desktop machine. If it works for his needs on his system then it's good enough for everyone so quit your whinging. WONTFIX NOTABUG USERERROR. systemd as init is fine, it's a shame it incompetently tries to do much more than it should.

So, first disable systemd-resolved with:

systemctl stop systemd-resolved
systemctl disable systemd-resolved

Then install a real recursive caching name-server (dnsmasq, unbound, bind, or whatever) and configure it to forward requests for your hosts.virsh domain to

With dnsmasq, you'd use something like --server=/hosts.virsh/

With bind, define a forwarding zone in your named.conf like this:

zone "hosts.virsh" {
        type forward;
        forwarders {; };

With Unbound, something like:

name: "hosts.virsh."

If this nameserver is configured to listen on all IP addresses (or, at least, to an address reachable by your LAN), it can also act as a caching resolver for other machines on your network. IMO every network should have a caching resolver on it, sub-ms response times for cached DNS resolution is better than milliseconds or 10s or even 100s of milliseconds.

If you're already using dnsmasq for your VMs, it should be possible to configure it to work for both your VMs and your host (and other machines on your network) without needing a forwarder for hosts.virsh (that domain will already be part of its configuration).

I say "should" because I haven't tried as I don't use dnsmasq. Instead, I use ISC dhdcpd and bind9 and hard-code fixed IP addresses based on MAC address in my dhdpd.conf, and manually add entries for my VMs to my domain's zonefile.

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.