# 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.
[main]
dns=dnsmasq

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

# 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 127.0.0.1 and a new dnsmasq process spawned.

cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 127.0.0.1


### 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
server=/qxyz.intra/192.168.122.1


### 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'>
<name>default</name>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr0' stp='on' delay='0'/>

sudo hostnamectl set-hostname neon.qxyz.intra