mDNS on Ubuntu Server
Recently I was configuring a virtual network of several KVM machines for the testing of Gitlab installation. It’s more convenient when I can access machines by hostname but I don’t want to install and support a DNS server. So I’d decided to use mDNS.
First of all, I’d tried to configure mDNS using Netplan — the default network configuration tool in Ubuntu. I’d found nothing about mDNS support in Netplan documentation. There is a ticket on the launchpad about this issue and it was marked as resolved, but I’d found no changes in the master branch the Netplan’s Github, connected to mDNS. I’m sure this feature will be implemented in the future, but for now, it’s impossible to configure mDNS with Netplan.
Ubuntu Server 20.04 uses systemd-resolved as a DNS configuration tool. It supports mDNS, but by default mDNS is disabled. To use mDNS it’s required to enable it globally and for a particular network interface.
To enable mDNS globally I need to set option MulticastDNS=yes
in the /etc/systemd/resolved.conf
file. According to the
man page to turn on mDNS
for enp1s0
network interface I need to create a file /etc/systemd/network/enp1s0.network
and add
MulticastDNS=yes
option there. This solution does not work out of the box, because Netplan creates
configuration file for the network interface in the /run
directory and this file has a higher
priority than the file in /etc
. It’s possible to enable mDNS with a command like
sudo systemd-resolve --set-mdns=yes --interface=enp1s0
but it’s a temporary solution that works
only until reboot.
In my case, Netplan creates more problems than benefits, so I’d decided to remove it completely and configure the network with systemd-network by hand.
To remove Netplan I’d executed the command sudo apt purge netplan.io
. And for the network
configuration I’d created file /etc/systemd/network/enp1s0.network
with such contents:
[Match]
Name=enp1s0
[Network]
MulticastDNS=yes
DHCP=ipv4
LinkLocalAddressing=ipv6
[DHCP]
RouteMetric=100
UseMTU=true
After the reboot, everything worked as expected.