Using the NetworkManager’s DNSMasq plugin

Page content

Imagine you want to test something in a demo setup with 5 machines. You create the necessary VMs in your local environment – but you cannot address them properly by name. With 5 machines you also need to write down the appropriate IP addresses – that’s hardly practical.

Luckily, there is an elegant solution: The dnsmasq plugin is a hidden gem of NetworkManager.

Enable NetworkManager’s dnsmasq

# /etc/NetworkManager/conf.d/00-use-dnsmasq.conf
# This enabled the dnsmasq plugin.
# /etc/NetworkManager/dnsmasq.d/00-homelab.conf
# This file sets up the local lablab domain and
# defines some aliases and a wildcard.

# The below defines a Wildcard DNS Entry.

# Below I define some host names.  I also pull in   
# /etc/NetworkManager/dnsmasq.d/02-add-hosts.conf
# By default, the plugin does not read from /etc/hosts.  
# This forces the plugin to slurp in the file.
# If you didn't want to write to the /etc/hosts file.  This could
# be pointed to another file.

Restart your network managger systemctl restart NetworkManager. If everything is working right, you should see that your resolv.conf points to and a new dnsmasq process spawned.

cat /etc/resolv.conf
# Generated by NetworkManager

Configurate NetworkManager fo libvirt’s domain

Libvirt comes with its own in-build DNS server, dnsmasq to serve DHCP and DNS to servers for vms. Additionally, NetworkManager can be configured to use its dnsmasq plugin to forwarding DNS requests to the libvirt instance if needed.

# /etc/NetworkManager/dnsmasq.d/01-libvirt_dnsmasq.conf

Configuring libvirt

First of all, libvirt needs to be configured. Given that the network “default” is assigned to the relevant VMs, the configuration should look like this:

sudo virsh net-edit 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 VM guests

sudo hostnamectl set-hostname neon.qxyz.intra