Automatic DNS resolution for libvirt guests using a local domain

Published: 19 February 2020

Note: this article is old and may contain outdated or incorrect information.

Configuring libvirt

First libvirt needs to be configured. Modify the default network using virsh net-edit default.

$ sudo virsh net-dumpxml default
<network connections='1'>
  <name>default</name>
  <uuid>3a3627c2-15a7-4e7f-b7b6-0c2310ba9427</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:fa:cb:e5'/>
  <domain name='lab.offdutypirate.com' localOnly='yes'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.128' end='192.168.122.254'/>
    </dhcp>
  </ip>
</network>

Configuring the guests

$ hostnamectl set-hostname bigbox.lab.offdutypirate.com

Configuring NetworkManager

The NetworkManager configuration must be updated to enable the internal dnsmasq service as well as configuring the domain set above. Modify the configuration files as below with the correct domain name and subnet.

# add to /etc/NetworkManager.conf

[main]
dns=dnsmasq}
# add to /etc/NetworkManager/dnsmasq.d/libvirt_dnsmasq.conf
server=/lab.offdutypirate.com/192.168.122.1

References