Multicast DNS (mDNS)
Multicast DNS (mDNS)
Overview
- Multicast DNS (mDNS)
- DNS-Based Service Discovery
- Link-local Multicast Name Resolution (LLMNR)
- Home Networking Control Protocol
- Avahi
- nss-mdns
- Download ISC’s software
- Mdns daemon for OpenBSD
- Mdns daemon not support IPv6 yet
- Local name resolution in windows networks#11
- Local name resolution in Linux
Multicast DNS (mDNS) is a way of using familiar DNS programming interfaces, packet formats and operating semantics, in a small network where no conventional DNS server has been installed.
Multicast DNS (mDNS) is a joint effort by participants of the IETF Zero Configuration Networking (zeroconf) and DNS Extensions (dnsext) working groups. The requirements are driven by the Zeroconf working group; the implementation details are a chartered work item for the DNSEXT group. Most of the people working on mDNS are active participants of both working groups.
Multicast DNS (mDNS) provides the ability to perform DNS-like operations on the local link in the absence of any conventional Unicast DNS server. In addition, Multicast DNS designates a portion of the DNS namespace to be free for local use, without the need to pay any annual fee, and without the need to set up delegations or otherwise configure a conventional DNS server to answer for those names.
The primary benefits of Multicast DNS are that:
- mDNS require little or no administration or configuration to set them up
- mDNS work when no infrastructure is present
- mDNS work during infrastructure failures
Avahi is a free Zero-configuration networking (zeroconf) implementation, including a system for multicast DNS/DNS-SD service discovery. It allows programs to publish and discover services and hosts running on a local network with no specific configuration.
Protocol overview
When an mDNS client needs to resolve a hostname, it sends an IP multicast query message that asks the host having that name to identify itself. That target machine then multicasts a message that includes its IP address. All machines in that subnet can then use that information to update their mDNS caches. Any host can relinquish its claim to a name by sending a response packet with a time to live (TTL) equal to zero.
By default, mDNS exclusively resolves hostnames ending with the .local top-level domain. This can cause problems if .local includes hosts that do not implement mDNS but that can be found via a conventional unicast DNS server. Resolving such conflicts requires network-configuration changes that mDNS was designed to avoid.
Packet structure
An mDNS message is a multicast UDP packet sent using the following addressing:
- IPv4 address 224.0.0.251 or IPv6 address ff02::fb
- UDP port 5353
- When using Ethernet frames, the standard IP multicast MAC address 01:00:5E:00:00:FB (for IPv4) or 33:33:00:00:00:FB (for IPv6)
The payload structure is based on the unicast DNS packet format, consisting of two parts — the header and the data.
The header is identical to that found in unicast DNS, as are the sub-sections in the data part: queries, answers, authoritative-nameservers, and additional records. The number of records in each sub-section matches the value of the corresponding COUNT field in the header.
Install Avahi
1 | sudo apt-get install -y --no-install-recommends avahi-daemon libnss-mdns |
Using Avahi
Hostname resolution
Avahi provides local hostname resolution using a “hostname.local” naming scheme. To enable it, install the nss-mdns package and start avahi-daemon.service.
Then, edit the file /etc/nsswitch.conf and change the hosts line to include mdns_minimal [NOTFOUND=return] before dns:
1 | sudo vi /etc/nsswitch.conf |
Configuring mDNS for custom TLD
The mdns_minimal module handles queries for the .local TLD only. Note the [NOTFOUND=return], which specifies that if mdns_minimal cannot find *.local, it will not continue to search for it in dns, myhostname, etc.
In case you want Avahi to support other TLDs, you should:
- replace mdns_minimal [NOTFOUND=return] with the full mdns module. There also are IPv4-only and IPv6-only modules mdns[46](_minimal)
- customize /etc/avahi/avahi-daemon.conf with the domain-name of your choice
- whitelist Avahi custom TLDs in /etc/mdns.allow
Avahi services discover tools
Avahi includes several utilities which help you discover the services running on a network. For example, run
1 | sudo apt-get install -y --no-install-recommends avahi-utils |
to discover services in your network.
Adding services to Avahi
The Avahi mDNS/DNS-SD daemon advertises the services whose *.service files are found in /etc/avahi/services/. Files in this directory must be readable by the avahi user/group. See avahi.service(5) for more details.
Firewall
Be sure to open UDP port 5353 if you’re using a firewall.
Windows
Windows 10 may not discover services by IPv4, but IPv6 works:
1 | PS C:\> ping -6 raspberrypi.local |
Windows 10 handles both hostname and hostname.local identically: it simultaneously tries LLMNR for the bare hostname, NetBIOS for the bare hostname, and (optionally) mDNS for hostname.local.
To activate the mDNS support, you have to Turn off the Link Local Multicast Name Resolution (LLMNR), i.e. set the EnableMulticast registry value to 0 (0: Disable LLMNR, 1: Use LLMNR):
1 | PS C:\> netsh dnsclient show state |