Using the NetworkManager’s DNSMasq plugin
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.
address=/.ose.homelab/192.168.101.125
# Below I define some host names. I also pull in
address=/openshift.homelab/192.168.101.120
address=/openshift-int.homelab/192.168.101.120
# /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.
#
addn-hosts=/etc/hosts
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>
<uuid>158880c3-9adb-4a44-ab51-d0bc1c18cddc</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='qxyz.de' 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 VM guests
sudo hostnamectl set-hostname neon.qxyz.intra