Multicast DNS (MDNS) on Home Networks

mDNSMulticast DNS is part of Zero-configuration networking (zeroconf) set of technologies designed to enable devices to work on networks without manual setup.

The Multicast DNS  protocol is used to locate a device or service by name on a small local network without using a preconfigured name sever i.e DNS.

Originally developed by Apple it goes under the name of Bonjour. It is an Internet standard Multicast DNS RFC 6762.

Multicast DNS uses the same packet structure and commands as DNS, but doesn’t rely on a user configured DNS server.



Instead computers on a network create their own local DNS records and store them locally in cache. (computer memory).

In this tutorial you will learn  how the mDNS protocol works and how to perform mDNS queries using the avahi utility tools, and the dns-sd tool from the Bonjour sdk.

Quick Links

mDNs on Linux and Windows

On Linux including the Raspberry Pi it is usually installed automatically and uses Avahi packages .

You can also download the utilities which can be useful for troubleshooting using:

sudo apt-get install avahi-utils.

On windows and Apple the mDNS services are provided by the Bonjour packages.

bonjour-sdkYou can download the Bonjour SDK here which will allow you to use the dns-sd command line tool.

You will need to create a developer account to download the SDK.

How mDNS Works

It is useful to compare mDNS with the traditional DNS service especially if you are familiar with DNS.

When a host requires to know the IP address of another host is send a DNS query to a DNS server using a unicast UDP message on port 53.

The address of this DNS server is part of the network configuration of the host.

With mDNS no mDNS server is preconfigured, and the host uses a multicast query on IPv4 address 224.0.0.251 or IPv6 address ff02::fb and UDP port 5353.

Note: Multicast is a method on IP networks of sending data to a group of computers.

All mDNS hosts see this query and the host that has this network name responds to the query using a multicast message that contains it’s IP address.

Because messages were exchanged using multicast all other mDNS hosts see this exchange and can make a note of the network name and IP address, and store this in their local cache.

All mDNS hosts now know the name and IP address of the requested host.

So the process is:

  • Host A sends query for IP address of Host Z.
  • All mDNS hosts see this query.
  • Host Z responds with it’s IP address
  • All mDNS hosts see this response.
  • All mDNS hosts update their local cache with the name host Z and it’s IP address.

The .local Domain Name

All DNS entries have a domain name and for devices and services on local networks that aren’t part of the global DNS namespace the .local domain name was reserved.

This means that all hosts on a local network will have a name of the form.

host1.local

The mDNS resolver on the client registers the host with the .local prefix.

So when you do a ping on a local network you would use:

ping ws6.local

for a computer called ws6 on your local network. The local name resolver will automatically choose mDNS as a first choice to resolve the name because of the presence of the .local suffix.

mDNS Records

mDNS supports both host name records (A and AAAA) record types and SRV records as in standard DNS.

Because of this mDNS can be used for locating hosts and services on a local network.

The service record structure can appear confusing at first glance for any one new to DNS service records.

The structure (taken from wiki) is shown below along with an example record:

_service._proto.name. TTL class SRV priority weight port target.
_sip._tcp.example.com. 86400 IN SRV 0 5 5060 sipserver.example.com.

Here

the service is _sip
the proto name is tcp //protocol service uses
the name is example.com. // domain name for which it is valid.

You should notice the use of the underscores in the structure.

At the end of the record we have

port target

The port is the port the service runs on (5060) and the target is the host that runs this service ( sipserver.example.com. )

Announcements

As part of the mDNS protocol mDNS devices will make announcements containing their mDNS records on start and in response to network changes on the host machine.

These announcements will be received by all mDNS clients on the local network and are used to update their own records.

Service Discovery Using mDNS

mDNS can be used to discover services like MQTT on your local network.

Example Query

An mDNS client issues a query for that service as shown by using the avahi-browse utility below:

avahi-find-service-mqtt

You can see that this service is available on machine called pi2 and on both IPv4 and IPv6.

On Windows use the dns-sd -B service name command

mdns-tools-windows-1

Finding Hosts Using mDNS

This can be demonstrated using the avahi-resolve utility an example is shown below

avahi-resolve-host

On Windows use the dns-sd -Q hostname command

mDNS-tools-windows

Common Questions and Answers

Q- Can I still use a local domain name server like DNSMasq if my clients use mDNS.

A- Yes they co-exist on the same network.

Q- Can you use mDNS across VLANs?

A- Not without extra configuration.

Q- Can I use a host announce services that are available on other machines on the network?

A- Yes on Linux you will need to create and add a avahi services file. See Broadcast mDNS for another Device.

Q- What Port Does mDNS use.

A- The mDNS protocol uses UDP port number 5353

Resources



Related Tutorials

Please Let me Know if you found it Useful
[Total: 13 Average: 4.4]

6 comments

  1. This article needs to be updated. Product offerings and defaults have changed, which could lead someone into trouble if they follow the recommendations in the article blindly.

    Specifically-

    Linux platforms that are systemd based now use systemd-resolved to handle mdns, not Avahi. Installing avahi on one on these machines can lead to port conflicts and break mdns.

    Windows10/11 now have native mdns support and don’t rely on Bonjour. Again installing Bonjour on these machines without disabling the default mdns service can cause conflicts.

    Note-
    The native Win10 mdns service lacks tracing and debugging tools. Some info on how to monitor and debug mdns on windows with the native services would be very useful.

  2. I on the other hand never consider it a waste of time to read what Steve posts. I always learn something. He has a nack for explaining things very well.

  3. I stopped reading because it is my experience that unchecked posts like this with mistakes continue to be unreliable. What did I notice:
    sudo apt-get avahi-utils.
    OOPS – apt-get requires a command, I think you meant:
    sudo apt-get install avahi-utils.

Leave a Reply

Your email address will not be published. Required fields are marked *