This guide walks you through mDNS and Avahi on Linux, for anyone who needs a handful of machines to find each other by name on the same network. mDNS is multicast DNS, where every machine answers name lookups for itself instead of everyone asking a central DNS server, and Avahi is the Linux program that does it. Apple ships the same protocol as Bonjour, and the wider approach is called Zeroconf because nothing has to be configured by hand. It earns its keep when a printer, a build box and three test VMs all need a .local name and nobody wants to edit a DNS zone every time one of them changes. The short answer is to install avahi-daemon on the hosts that should be findable, open UDP port 5353 for multicast, and turn on Avahi’s reflector only if discovery has to cross VLANs.
How to verify
Inspect what Avahi sees and publishes:
avahi-browse --all --resolve --terminate
avahi-resolve --name printer.local
avahi-publish --service "test" _http._tcp 8080 &
ss -ulnp 'sport = :5353'
tcpdump -ni any port 5353 -c 20
systemctl status avahi-daemon
avahi-browse --all --resolve --terminate walks every known mDNS service type on the local segment and prints what it finds; it is the equivalent of dig ANY for service discovery.
What’s happening
mDNS uses UDP port 5353 on the multicast address 224.0.0.251 (IPv4) or ff02::fb (IPv6). The TTL on the IP header is 1 — the spec mandates that mDNS frames never cross a router. Two protocols layer on top:
- mDNS answers DNS-style queries for hostnames in
.local. Each host that owns a name responds for itself. - DNS-SD (DNS-Based Service Discovery, RFC 6763) sits on top of mDNS and provides the conventional service-type strings like
_http._tcp.local,_ssh._tcp.local,_ipp._tcp.local. Browsers and printers use DNS-SD to enumerate available services.
Avahi runs as a daemon publishing the local host’s name and any service files in /etc/avahi/services/. Other hosts query for _services._dns-sd._udp.local to enumerate available service types, then for each type to find instances. Avahi answers and caches both.
The link-local restriction matters operationally. mDNS works across a single L2 broadcast domain only. To cross VLANs you need a reflector that listens on multiple interfaces and rebroadcasts mDNS traffic between them — Avahi has this built in, but enabling it requires thought about which devices should be discoverable across boundaries.
The procedure
-
Confirm Avahi is installed and the daemon is running on hosts that should publish.
apt install avahi-daemon avahi-utils systemctl enable --now avahi-daemonDisable it on servers that should not publish (DB servers, internal API hosts):
systemctl disable --now avahi-daemon -
Configure publishing scope. Edit
/etc/avahi/avahi-daemon.conf:[server] host-name=host01 domain-name=local use-ipv4=yes use-ipv6=yes allow-interfaces=eth0 ratelimit-interval-usec=1000000 ratelimit-burst=1000 [publish] publish-addresses=yes publish-hinfo=no publish-workstation=no publish-domain=yes [reflector] enable-reflector=no -
Publish a service. Drop a file in
/etc/avahi/services/:<!-- /etc/avahi/services/ssh.service --> <?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.xml"> <service-group> <name replace-wildcards="yes">SSH on %h</name> <service> <type>_ssh._tcp</type> <port>22</port> </service> </service-group>Reload:
systemctl reload avahi-daemonBrowse from another host:
avahi-browse -r _ssh._tcp -
Allow mDNS through the firewall.
iptables -A INPUT -p udp -d 224.0.0.251 --dport 5353 -j ACCEPT ip6tables -A INPUT -p udp -d ff02::fb --dport 5353 -j ACCEPTOr for nftables:
ip daddr 224.0.0.251 udp dport 5353 accept ip6 daddr ff02::fb udp dport 5353 accept -
Enable the reflector to bridge VLANs. Caution — this exposes services from one VLAN to another. Set explicit allow-list:
[reflector] enable-reflector=yes reflect-ipv=no [server] allow-interfaces=eth0,eth1The reflector only forwards records, not queries; some clients are sensitive to seeing answers from non-local sources and will refuse them. AirPlay receivers in particular are picky.
-
Verify reflection is bidirectional. From a host on VLAN A, run
avahi-browse -r _ssh._tcpand confirm services on VLAN B appear. Reverse to confirm the other direction.
Operational notes
- Avahi publishes the host’s MAC and hostname by default, including on interfaces facing untrusted networks. On any internet-exposed host disable
publish-addressesandpublish-workstation, or just remove the daemon. - Reflector mode disables IGMP snooping benefits. Reflected mDNS arrives at every host on the second VLAN regardless of subscription; this is fine for a handful of clients but scales poorly past hundreds.
- CUPS Bonjour browsing requires Avahi. A CUPS server published via Avahi appears in macOS print dialogs automatically; disabling Avahi means clients have to enter the queue URL manually.
.localcollides with split-DNS suffixes. Active Directory used.localas the default forest TLD for years, and that conflicts with mDNS resolution. The standard fix is to switch the AD domain off.local; a workaround is to disable mDNS resolution on affected clients.- WiFi multicast rate-limiting kills mDNS. Many APs rate-limit multicast to a slow basic rate; on busy networks mDNS responses get dropped, and service discovery becomes erratic. Switch the AP to a higher multicast rate if your hardware allows.
In the engagements we run, Avahi is one of the daemons we audit on every host. On dev workstations and lab equipment it stays; on servers it gets disabled by default. When clients want printer or AirPlay discovery across subnets, we deploy a controlled reflector with a documented service whitelist — same pattern as the PIM-SM multicast piece but at L2. The Ansible role that ships with the managed-operations practice enforces this configuration as part of host baseline.