Configuring mDNS for Easy Access to Devices

From max.wiki
Revision as of 06:27, 20 February 2026 by Mxl (talk | contribs) (Created page with "[https://en.wikipedia.org/wiki/Zero-configuration_networking Zeroconf] consists of a number of related concepts with the common objective of making simple networked services "just work". Initially it was implemented by Apple as Bonjour, but on Linux the re-implementation [https://en.wikipedia.org/wiki/Avahi_(software) Avahi] is usually used to provide Zeroconf. Although initially intended for discovering networked devices like printers or speakers, it can also be useful...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Zeroconf consists of a number of related concepts with the common objective of making simple networked services "just work". Initially it was implemented by Apple as Bonjour, but on Linux the re-implementation Avahi is usually used to provide Zeroconf. Although initially intended for discovering networked devices like printers or speakers, it can also be useful for accessing other hosts or smart home devices on the local network without hard-coding their address or hosting a name server.

The relevant concept in Zeroconf that makes this work is multicast DNS (mDNS) which can resolve hostnames inside a local network by using multicast broadcasts. The mDNS client sends a multicast broadcast asking for <name>.local, and the host with the given name (typically the device's hostname) answers it. My goal was to make various devices on my home network accessible over their mDNS address. This works unreliably out of the box, I've collected the steps I took to get it working more reliably.

MDNS is easily conflated with DNS service discovery (DNS-SD), which allows discovering specific services (e.g. print service, web server, etc.) once a host is known. Both are relevant, however technically these are two separate concepts under Zeroconf.

Analyzing the Network

To get a more or less complete list of DNS-SD services on the network, use the command avahi-browse --resolve --terminate --all. This uses both mDNS and DNS-SD via the Avahi daemon. For more details, see https://askubuntu.com/a/1105895.

To use mDNS to resolve a hostname, use avahi-resolve-host-name <name>.local. This returns only a single resolved address, even if the host has multiple. To at least reliably get an IPv4 or an IPv6 address, pass -4 or -6.

Becoming Discoverable

While some devices are easily accessible, some need more work.

Avahi (Linux)

The Avahi Daemon, as typically configured on Linux distributions, does not answer mDNS queries, because it is not configured to provide any services. To publish a "workstation" service, effectively advertising only that the host exists, a change is required in the config file (probably /etc/avahi/avahi-daemon.conf):

publish-workstation=yes

This supposedly used to be the default in earlier versions, but was changed for security reasons. Using a firewall on untrusted networks is a good idea anyway!

Restart the Daemon afterwards with sudo systemctl restart avahi-daemon.service.

Android

https://source.android.com/docs/core/ota/modular-system/dns-resolver#mdns-local-resolution

https://old.reddit.com/r/synology/comments/sk8dzz/cannot_ping_mdns_address_servernamelocal_on/hvk0v5k/

As of Android 12, there is support for mDNS.

mDNS and IPv6

mDNS and Android

As of Android 12, Android supports mDNS to some extent.

Sources

https://askubuntu.com/a/1105895/254818