Skip to content

Instantly share code, notes, and snippets.

@jimmydo
Last active March 20, 2025 15:10
Show Gist options
  • Save jimmydo/e4943950427234408a1aaa2d7beda8b6 to your computer and use it in GitHub Desktop.
Save jimmydo/e4943950427234408a1aaa2d7beda8b6 to your computer and use it in GitHub Desktop.
Enable multicast DNS on Ubuntu Server

Enabling multicast DNS (mDNS) on a server allows other hosts on the local network to address the server as <hostname>.local.

mDNS is disabled by default in Ubuntu Server:

$ resolvectl mdns
Global: no
Link 2 (eno1): no

mDNS setup involves two config changes:

Multicast DNS will be enabled on a link only if the per-link and the global setting is on.

First, enable mDNS globally in /etc/systemd/resolved.conf:

[Resolve]
...
MulticastDNS=yes
...

Next, we have to enable mDNS on the network interface. Ubuntu Server uses netplan to render network config files into /run/systemd/network. But netplan doesn't yet support mDNS configuration, so we need to augment the main network file with a drop-in file.

Determine the name of the main network file:

$ ls /run/systemd/network
10-netplan-eno1.network

Create the drop-in directory based on the name of the main network file:

$ mkdir /etc/systemd/network/10-netplan-eno1.network.d

Create the drop-in file at /etc/systemd/network/10-netplan-eno1.network.d/override.conf containing:

[Network]
MulticastDNS=yes

Reboot to apply the new configuration.

Verify that mDNS is enabled:

$ resolvectl mdns
Global: yes
Link 2 (eno1): yes
@gkapellmann
Copy link

Hi @jimmydo, great explanation. I am wondering though, if this should work in a VM with ubuntu server? I followed the instructions as stated in a VM running in a TrueNAS Scale OS, the VM is running Ubuntu 24.04 LTS.

But unfortunately I got no success, any idea of what I could be missing?

@roolebo
Copy link

roolebo commented May 24, 2024

It's sufficient to change only /etc/systemd/resolved.conf on 24.04 to get mDNS. It gets enabled for all interfaces.

@gkapellmann
Copy link

gkapellmann commented May 27, 2024

Hmmm, ok.

I have that file like this:

[Resolve]
#Some examples of DNS servers which may be used for DNS= and FallbackDNS=:
#Cloudflare: 1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com 2606:4700:4700::1111#cloudflare-dns.com 2606:4700:4700::1001#cloudflare-dns.com
#Google: 8.8.8.8#dns.google 8.8.4.4#dns.google 2001:4860:4860::8888#dns.google 2001:4860:4860::8844#dns.google
#Quad9: 9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
#DNS=10.0.0.138
#FallbackDNS=
#Domains=local
#DNSSEC=no
#DNSOverTLS=no
MulticastDNS=yes
#LLMNR=no
#Cache=no-negative
#CacheFromLocalhost=no
#DNSStubListener=yes
#DNSStubListenerExtra=
#ReadEtcHosts=yes
#ResolveUnicastSingleLabel=no
#StaleRetentionSec=0

That should do, right?

But for some reason it is not working. I tried resolvectl status ens3 (which is my interface) and doesnt seem to be activated:

Link 2 (ens3)
Current Scopes: DNS
Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported

@roolebo
Copy link

roolebo commented May 27, 2024

@gkapellmann do manage network with systemd-networkd or network manager?

@gkapellmann
Copy link

I believe its systemd-networkd, since I check the service and it is active.

@roolebo
Copy link

roolebo commented May 28, 2024

@gkapellmann yeah, if network is managed by systemd-networkd, then you need to create a drop-in setting to enable mDNS explicitly as defined above. netplan status tells if an interface is managed by NetworkManager or networkd.

On one of my hosts (with ubuntu-desktop component):

●  4: wlp94s0 wifi UP (NetworkManager: wlp94s0)

On another host (without ubuntu-desktop component):

●  2: enp1s0 ethernet UP (networkd: enp1s0)

Note that I had to explicitly stop and disable systemd-networkd service after I installed ubuntu-desktop. So if systemd-networkd is active it's not necessarily means networkd manages the network.

On the first host managed by NetworkManager it's sufficient to only change /etc/systemd/resolved.conf and restart systemd-resolved.
On the second host there's a need to create a override.conf as described in the gist and restart both systemd-resolved and systemd-networkd. A reboot is not mandatory to apply the changes.

@gkapellmann
Copy link

Right! I had done this before and didnt work... beacuse I had a one letter typo in the override.conf directory... my bad!

But learning this NetworkManager vs networkd detail has been very helpful!

Thank you for yor time!

@PabloZarateGarcia
Copy link

PabloZarateGarcia commented Jul 25, 2024

I edited the resolved.conf like shown here and did:
sudo resolvectl mdns enp2s0 true
And thats it, just replace enp2s0 with your interface. No need to reboot.

@Auradomix
Copy link

Damn that worked, thanks bro. I'm a beginner in this and I really liked the way raspberry pi offer the way to set hostname.local to access the device.

@FlorianHeigl
Copy link

FlorianHeigl commented Feb 7, 2025

the f... why would you need to reboot for restarting a service... don't let this stuff (*) mislead you. you never need to reboot unix.

("it" being the software and the interfaces it provides you, not the gist. The gist is great)

@cdalexndr
Copy link

after reboot I cannot access my remote server with ssh... this script is missing some pre checks

@brodo
Copy link

brodo commented Mar 18, 2025

@cdalexndr I had the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment