18

Ubuntu 18

I've done a ton of research and am close to pulling this picture together but can't quite understand:

How can I configure systemd-resolved for mdns?

My goal specifically:

  • to bring up a server on a 10.0.0.0/16 network
  • for the new server to give itself some arbitrary name like foo1
  • to be able to connect to that server from another machine on the same network using the name foo1

Can anyone tell me please how to make this happen specifically using systemd-resolved?

thanks

So far I have configured resolved.conf at follows on

ubuntu@ip-10-0-0-229:/etc$ --> CHROME -> cat /etc/systemd/resolved.conf
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details

[Resolve]
#DNS=
#FallbackDNS=
#Domains=
LLMNR=yes
MulticastDNS=yes
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes
ubuntu@ip-10-0-0-229:/etc$ --> CHROME ->
Duke Dougal
  • 965
  • 3
  • 16
  • 27

5 Answers5

21

This is a late answer but I still think that can help someone because there are few infos on this topic. I also wasted time on this problem.

Changing the /etc/systemd/resolved.conf is just a part of the work. After your changed it you still need to resolve this puzzle:

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

And if you know the trick... it's easy.

sudo systemd-resolve --set-mdns=yes --interface=wlan0

wlan0 is the interface where the mDNS is requested. After that, you can see that mDNS is activated:

$ sudo systemd-resolve --status wlan0            
Link 3 (wlan0)
      Current Scopes: none
 DefaultRoute setting: no
        LLMNR setting: yes
 MulticastDNS setting: yes #<--- BINGO! 
   DNSOverTLS setting: no
       DNSSEC setting: allow-downgrade
       DNSSEC supported: yes

Restart systemd-resolved via systemctl:

sudo systemctl restart systemd-resolved 

And mDNS is working!

(before)

~ ❯ ping homebridge.local                                    
ping: cannot resolve homebridge.local: Unknown host

(after)

~ ❯ ping homebridge.local                                    
PING homebridge.local (192.168.1.9): 56 data bytes
64 bytes from 192.168.1.9: icmp_seq=0 ttl=64 time=21.721 ms
64 bytes from 192.168.1.9: icmp_seq=1 ttl=64 time=22.429 ms
Simon A. Eugster
  • 431
  • 1
  • 3
  • 11
ozw1z5rd
  • 311
  • 2
  • 5
  • 1
    And the reason that we need to do this is because systemd as implemented by the distro vendors broke existing behavior. The reader would do well to check the new ---ntpd--- systemd-timesyncd configuration because SystemD is All. SystemD Is The Way. – Andrew Beals Apr 20 '20 at 13:49
  • 3
    same can be achieved with adding `MulticastDNS=yes` to the interface config file. For example for eth0, you can add it to `/etc/systemd/network/eth.network`. Otherwise, the steps you give don't persist across reboot – novelistparty Jun 04 '20 at 20:46
  • I think there's a typo `restart systems-resolved` Should that be `restart systemd-resolved` ? – Wyck May 17 '21 at 16:09
  • 1
    The output of `systemd-resolve --status wlan0` looks a bit different on systemd 248. It display `+mDNS` instead of `Multicast DNS setting: yes` to me. I assume they're equivalent – walnut_salami May 30 '21 at 06:24
  • 2
    For Ubuntu 22.04, use `resolvectl mdns yes` in place of `systemd-resolve`. – Zeyi Fan Jun 04 '22 at 04:48
7

In order to enable mDNS on an interface, you need to set the MulticastDNS= option in the [Network] section of the .network file for the interface in the 10.0.0.0/16 network.

This option defaults to disabled and needs to be enabled per interface.

You can also use the systemd-resolve --status command (available on systemd v237 shipped in Ubuntu 18.04, newer systemd replaced this command with resolvectl) to query the status of resolved, including options enabled for each network interface. If you see MulticastDNS setting: no for the Link interface where the 10.0.0.0/16 network, then that means it's not enabled yet.

filbranden
  • 21,113
  • 3
  • 58
  • 84
  • 1
    The network device is eth0 and there appears to be no .network files in the /etc directory anywhere. It appears that Ubuntu 18 is configured via /etc/netplan/50-cloud-init.yaml can you suggest where I should set the MulticastDNS= option in this setup? thanks! – Duke Dougal Aug 02 '18 at 03:47
  • 5
    I created /etc/systemd/network/eth0.network, containing: [Match] Name=eth0 [Network] MuticastDNS=yes but no luck after restarting networking with sudo systemctl restart systemd-networkd – Duke Dougal Aug 02 '18 at 04:02
  • Ugh netplan... I believe netplan will generate .network config files under /run/systemd/network, maybe take a look there and see what it's generating. I also think it's quite possible it doesn't support MulticastDNS= natively. If you do find which file it creates for eth0, then try `systemctl edit eth0.network` (assuming that's the file name), which will create a "drop-in" (assuming .network works with drop-ins?) where you can try to add the `[Network] MuticastDNS=yes`... Hopefully that helps? – filbranden Aug 02 '18 at 04:25
  • 1
    Unfortunately it seems that it's currently unsupported with Netplan: https://bugs.launchpad.net/netplan/+bug/1830507 – Pierz Sep 28 '19 at 17:24
  • @Pierz See my comment above, about using an additional drop-in file to add to the netplan generated configs. – filbranden Sep 28 '19 at 17:37
7

I spent a lot of time trying to get system-resolve working persistently after reboot, but couldn't get it to work to great frustration.

The steps I took as per instructions and comments above:

  • Set MulticastDNS=yes in /etc/systemd/resolved.conf
  • Created the file /etc/systemd/network/eth0.network with the following contents.
[Match]
Name=eth0

[Network]
MulticastDNS=yes

I tried following these instructions from the ArchLinux wiki using NetworkManager.

Nothing worked. So I finally decided to give up and go the systemd service route.

My solution

Update the multicast DNS (mDNS) settings for systemd-resolve, so that mDNS is enabled on the network link.

sudo nano /etc/systemd/resolved.conf

Update the following settings.

MulticastDNS=yes
LLMNR=no

Create a service that runs after systemd-resolved.service runs, to enable mDNS on the eth0 network link. This will ensure that the multicast DNS is persisted across reboots.

sudo nano /etc/systemd/system/multicast-dns.service

Add the following.

[Unit]
Description=Enable MulticastDNS on eth0 network link
After=systemd-resolved.service

[Service]
ExecStart=systemd-resolve --set-mdns=yes --interface=eth0

[Install]
WantedBy=multi-user.target

Enable the multicast-dns service.

sudo systemctl enable multicast-dns
sudo systemctl start multicast-dns
sudo systemctl status multicast-dns
sudo systemctl restart systemd-resolved

Let's test it.

# Protocols should show '+mDNS' instead of '-mDNS'
sudo systemd-resolve --status eth0
# The same information voor all network interface
resolvectl status
# Check if the hostname with .local added is resolved
resolvectl query `hostname`.local

Now reboot and system-resolve should be working out of the gate :-)

Hope this saves someone some frustration.

nidkil
  • 171
  • 1
  • 2
  • Thanks @nidkil. This worked for me in Ubuntu Server 20.04 inside VirtualBox (just had to use enp0s3 instead of eth0, which I found using ifconfig). – jeff-h Sep 27 '21 at 21:30
2

In addition to MulticastDNS=yes in your .network file, the same setting also needs to be set in resolved.conf. From resolved.conf doc:

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

thom_nic
  • 547
  • 8
  • 14
2

My way of dealing with mDNS (avahi) is this

• sudo apt install ifupdown
• sudo apt install avahi-utils

idea from text in

• cat /etc/network/interfaces 
• # ifupdown has been replaced by netplan(5) on this system.  See
• # /etc/netplan for current configuration.
• # To re-enable ifupdown on this system, you can run:
• # sudo apt install ifupdown
user75786
  • 21
  • 2
  • Avahi doesn't play nice with aliased network interfaces though. For example it is impossible to configure two separate hosts (and respective services) for two different IPs on the same network interface. This makes Avahi unsuitable for publishing services of nodes on an isolated subnet via NAT. – Coder Guy Apr 21 '23 at 20:16