Automatic DNS resolution for libvirt guests using a local domain

February 19, 2020 in memos.

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'>
  <forward mode='nat'>
      <port start='1024' end='65535'/>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:fa:cb:e5'/>
  <domain name='' localOnly='yes'/>
  <ip address='' netmask=''>
      <range start='' end=''/>

Configuring the guests

$ hostnamectl set-hostname

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

# add to /etc/NetworkManager/dnsmasq.d/libvirt_dnsmasq.conf