A question went out to the whole network: who is printerbox.local? There was no DNS server to ask and no router keeping a list. 0.6 milliseconds later, the machine with that name answered, and it answered everyone at once, broadcasting its own address to every device listening. Asked a second way, from an ordinary program, the same machine replied privately and promised its answer was good for only ten seconds. Asked for a name nobody owned, the network said nothing at all. Three queries, three different behaviors, all written down in a 2013 standard. This post reproduces them with Avahi on two Linux network namespaces, with every packet captured.
What mDNS replaces
DNS without a server
Ordinary DNS needs a server that knows the names. Home and office networks rarely have one that knows about the printer, the Raspberry Pi or the NAS. Multicast DNS, specified in RFC 6762 in February 2013, removes the server. Each device answers for its own name, and questions are sent to everyone.
The .local rule
The RFC reserves one domain for this: “any fully qualified name ending in “.local.” is link-local.” And it fixes where such questions go: “Any DNS query for a name ending with “.local.” MUST be sent to the mDNS multicast address,” which for IPv4 is 224.0.0.251, carried over UDP port 5353. That’s why .local names only work on the local network: multicast to 224.0.0.251 doesn’t cross routers.

The lab
Two machines and Avahi
Two Linux network namespaces were joined by a virtual Ethernet link: one at 10.88.0.1, one at 10.88.0.2. The second ran avahi-daemon 0.8, the standard mDNS responder on Linux, configured with the host name printerbox. Avahi logged its state as running [printerbox.local]. The first machine sent queries from a short Python script using the dnspython library, while tcpdump recorded everything on port 5353.
Why a script and not ping
On a normal desktop, ping printerbox.local just works, because the system’s name lookup passes .local names to Avahi. Sending the queries by hand made it possible to control exactly how each question was asked and to see each answer in full.
Three questions, three answers
A full mDNS query
The script first asked the way an mDNS-aware program does: from UDP port 5353, to 224.0.0.251. The capture showed the response:
10.88.0.2.5353 > 224.0.0.251.5353: 0*- [0q] 1/0/0 printerbox.local. (Cache flush) A 10.88.0.2
The answer went to the multicast address, not back to the asker. Every listening device received it and could cache it. The record carried a TTL of 120 seconds and no copy of the question. tcpdump labeled it “Cache flush,” and the parsed reply showed its class as CLASS32769, which is 0x8001: the normal Internet class with its top bit set. RFC 6762 defines that bit: the owner “sets the most significant bit of the rrclass field,” telling neighbors “this is not a shared record type,” so they should throw away any older address they held for the name.
A legacy query from an ordinary program
The second query came from a random port, the way a plain DNS client would send it, with query ID 4242. This time the reply went straight back to the asker’s port, by unicast:
10.88.0.2.5353 > 10.88.0.1.45601: 4242*- q: A (QM)? printerbox.local. 1/0/0 printerbox.local. A 10.88.0.2
The ID was echoed, the question was repeated, and the TTL dropped to 10 seconds. That’s RFC 6762 section 6.7 exactly: the responder “MUST send a UDP response directly back to the querier, via unicast,” must “repeat the query ID and the question,” and the TTL “SHOULD NOT be greater than ten seconds.” A short TTL keeps programs that don’t understand mDNS from caching an address that may change.
A name nobody has
The third query asked for nothere.local. The capture showed the question go out and nothing come back. The script gave up after three seconds with timeout. There’s no NXDOMAIN in this situation because there’s no one to send it: no device owns that name, so no device speaks. That silence is why a mistyped .local name tends to hang for a few seconds before failing, rather than failing instantly the way an unknown regular DNS name does.

How Linux sends .local lookups to Avahi
nsswitch.conf
Programs don’t talk to Avahi directly. They call the system resolver, which reads the hosts: line in /etc/nsswitch.conf. After installing the libnss-mdns package on Ubuntu, that line read:
hosts: files mdns4_minimal [NOTFOUND=return] dns
Reading the line
Lookups go left to right. files checks /etc/hosts. mdns4_minimal handles .local names; the nss-mdns project page says the minimal modules “will always deny to resolve host names that don’t end in .local.” [NOTFOUND=return] means that if mDNS says a .local name doesn’t exist, the lookup stops there instead of leaking the question to the regular DNS server. Everything else falls through to dns.
Avahi has to be running
The same page is explicit: “Avahi is a hard dependency when nss-mdns is used.” The module “tries to contact a running avahi-daemon,” and without it “the lookups will fail.” A machine that can’t resolve .local names usually has one of two problems: avahi-daemon isn’t running, or the hosts: line has no mdns entry.
Finding services, not just names
DNS-SD rides on top
Names are only half of what mDNS carries. A companion standard from the same month, RFC 6763, “DNS-Based Service Discovery,” uses ordinary DNS record types to advertise what a device offers. It names each advertised service as “_services._dns-sd._udp.local, that lets tools “find the list of advertised service types on the network.” This is how a laptop finds printers it has never been told about.
A web server, advertised
For a second round, Avahi on the lab machine was given a service file advertising a web server called “Lab Web Server” of type _http._tcp on port 8080, with one extra setting, path=/status. Then the questions went from general to specific:
_services._dns-sd._udp.local. 10 IN PTR _http._tcp.local.
_http._tcp.local. 10 IN PTR Lab\032Web\032Server._http._tcp.local.
Lab\032Web\032Server._http._tcp.local. 10 IN SRV 0 0 8080 printerbox.local.
Lab\032Web\032Server._http._tcp.local. 10 IN TXT "path=/status"
printerbox.local. 10 IN A 10.88.0.2
The first answer listed which kinds of service existed. The second named the instance (the \032 is an escaped space). Per RFC 6763, the SRV record “gives the port number and target host name,” here port 8080 on printerbox.local, and the TXT record “gives additional information about the service.” Avahi didn’t wait to be asked for everything: the answer to the _http._tcp question already included the SRV, TXT and A records, so a client could connect after a single round trip. Every record carried a 10-second TTL because the script asked as a legacy client from a random port; a full mDNS browser asking from port 5353 gets the longer lifetimes shown earlier.

Name conflicts
Two devices, one name
Because every device picks its own name, two can choose the same one. RFC 6762 handles this with probing: before claiming a name, a device asks whether anyone already has it. If two devices collide, section 9 says the device that loses “MUST cease using the name, and reconfigure.” In practice Avahi picks a new name by adding a number, so a second printerbox becomes printerbox-2.local. An attempt to show this in the lab didn’t run: both daemons tried to share the same process ID file, and the second refused to start.
Why a device’s name sometimes changes
This is the usual explanation when a Raspberry Pi or printer that has always been name.local suddenly answers as name-2.local: another device, or a stale copy of itself after a network blip, claimed the name first.
Troubleshooting .local names
A short checklist
- On the target: is
avahi-daemonrunning, and what name does it report? Its status line showsrunning [name.local]. - On the asker: does
/etc/nsswitch.confincludemdns4_minimalormdnson thehosts:line? - Are both machines on the same subnet? Multicast to 224.0.0.251 doesn’t cross a router.
- Is UDP port 5353 allowed by the firewall on both ends?
- On a desktop with
avahi-utilsinstalled,avahi-browse -a -r -tlists every advertised service, resolved to host and port, then exits. - Run
tcpdump -n udp port 5353and look for the question and the answer, exactly like the captures above.
When the network is the problem
Some Wi-Fi access points and managed switches filter or rate-limit multicast. If the query appears in a capture on the asker but never on the target, something between them is dropping it, and the fix is in the network equipment’s multicast or “mDNS” settings, not on either computer.
A domain clash worth knowing
Some organizations use .local as their internal DNS domain. On those networks, a name like server.local might be meant for the company DNS server while the operating system sends it to mDNS, or the other way around. The [NOTFOUND=return] rule in nsswitch.conf is one place that conflict shows up.
Sources
- RFC 6762, “Multicast DNS”: https://www.rfc-editor.org/rfc/rfc6762.html
- RFC 6763, “DNS-Based Service Discovery”: https://www.rfc-editor.org/rfc/rfc6763.html
- nss-mdns project: https://github.com/lathiat/nss-mdns
