16

Recently I came across avahi-daemon and mdns....

Do I need a mDNS client in my system to connect with mDNS server?

Or is there any other way to connect a computer without mDNS client to a mDNS server computer (hostname.local)?

Is it possible to ping from computer without mDNS service running.

Kurt Pfeifle
  • 4,785

2 Answers2

28

1. What is mDNS?

To get the overall picture, you need to look at something named Zeroconf. The Zeroconf concepts were implemented first and fully by Apple, but Apple use the marketing name Bonjour (initially Rendezvous) for it. mDNS (multicast DNS) is part of this -- see below.

Apple uses Bonjour for...

  • ...AirPrint (when iOS mobile clients are looking for an available printer in the LAN which they can use for "driverless printing"), or for

  • ...CUPS printer shares to be published in the LAN, or for

  • ...iTunes music library sharing on the LAN, and for

  • ...many other services which should work without a central DNS server to be installed, configured and maintained.

Under Linux, these same concepts were implemented by the Avahi project.

Bonjour/Zeroconf has 3 major goals:

  1. Allocate IP addresses without a DHCP server.
  2. Translate between host names and IP addresses without a DNS server.
  3. Discover services (like print providers) without a directory server like LDAP and make it easy to use them.

The complete technical Zeroconf concepts are specified in a series of RFCs, mainly:

  • IPv4LL / rfc3927 for assigning Link-Local IP addresses without a DHCP server.
  • mDNS / rfc6762 for multicast DNS to resolve hostnames without a central DNS server.
  • DNS-SD / rfc6763 for DNS-based Service Discovery without a central directory server.

One of the principal architects of Zeroconf was Stuart Cheshire. After writing down his thoughts about how to implement Apple's original ease of use AppleTalk Name-Binding Protocol over TCP/IP networking Stuart got hired by Apple to help implement the Zeroconf concept for Mac devices. He then also was a principal author of the above linked RFC documents.

Apple's Bonjour implementation is also available for Windows and Linux (although on Linux there is also an independent implementation named Avahi) as Open Source under the Apache License v2.0.

IANA runs a service names and ports registry, where developers who wish to define and develop new service types for their systems can reserve and register names for them.

2. Is it possible to make an mDNS query without an mdns service running?

Yes, it is.

Just run

avahi-browse -a

to get a continuously updated list of service announcements from all nodes on your LAN and the services they offer. A more verbose output is listed by

avahi-browse -v -a -t

The -t here also terminates the command automatically (and doesn't auto-update the list) after it can be assumed to have all currently active services discovered.

You can browse for IPP-enabled (Internet Printing Protocol) printers like this:

avahi-browse  _ipp._tcp  -r -t

The -r will "resolve" the found services and show a human readable name for them. The _ipp._tcp is the (weird) name encoding for services you need to get used to if you study this topic in more details. In this case it is the precise syntax to be used for IPP services in the LAN. Example output for above command:

+  wlan1 IPv4 Officejet 6500 [F051B9]                       Internet Printer     local
=  wlan1 IPv4 Officejet 6500 [F051B9]                       Internet Printer     local
   hostname = [HPA0B3CCF051B9.local]
   address = [192.168.78.24]
   port = [631]
   txt = ["Scan=T" "Duplex=F" "Color=T" "UUID=1c852a4d-b800-1f08-abcd-a0b3ccf051b9" "note=" "adminurl=http://HPA0B3CCF051B9.local." "mac=a0:b3:cc:f0:51:b9" "priority=30" "usb_MDL=Officejet 6600" "usb_MFG=HP" "product=(HP Officejet 6600)" "ty=Officejet 6600" "URF=CP1,MT1-2-8-9-10-11,OB9,OFU0,PQ3-4-5,RS300-600,SRGB24,W8,DEVW8,DEVRGB24-48,ADOBERGB24-48,IS1" "rp=ipp/printer" "pdl=application/vnd.hp-PCL,image/jpeg,application/PCLm,image/urf" "qtotal=1" "txtvers=1"]

You can also browse for services in a different domain, which exposes these to The Internet. One example domain were you may succeed with this (most of the time) is dns-sd.org:

  avahi-browse --domain=dns-sd.org -a -v -r

I've copied part of this answer from the Bonjour tag info over at AskDifferent. However, most of this tag info article was written by me anyways, so I don't at all feel bad about it....

Kurt Pfeifle
  • 4,785
0

I suggest the following method without avahi installation. But using usual dns client. Install dig. and make the query

# dig -4 @224.0.0.251 -p 5353  debian12-c1.local

it will tell the error but it doesnt matter

;; communications error to 224.0.0.251#5353: timed out

at the second terminal launch tcpdump like so

# tcpdump -n 'udp port 5353' -i enp0s3

07:25:12.670775 IP 172.16.10.12.36417 > 224.0.0.251.5353: 41633+ [1au] A (QM)? debian12-c1.local. (58)

07:25:12.672696 IP 172.16.10.11.5353 > 172.16.10.12.36417: 41633*- 1/0/0 A 172.16.10.11 (51)

you can clearly see the answer

debian12-c1.local. has IP=172.16.10.11

===
Another way to make mdns queries without avahi installation is clumsy but usually doesnt need to install anything in addition. If you use systemd-resolved for dns resolution then it has mdns server+mdns client. You just need to activate it.

Step one
check if mdns is activated in global section

# resolvectl  status | grep Global -A1
Global
         Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported  

we see +mDNS

if it differs then create a file

# cat /etc/systemd/resolved.conf.d/global.conf

[Resolve]

MulticastDNS=yes

and restart the daemon, check again

Step Two You need to activate mdns on an interface, for instance enp0s3

 # resolvectl mdns enp0s3   yes

check the setting

# resolvectl status  | grep enp0s3 -A1
Link 2 (enp0s3)
    Current Scopes: DNS mDNS/IPv4 mDNS/IPv6

we see mDNS in "Current Scopes"

This setting survives the daemon restart but does not survive pc restart.

If everything okay we will have two things:
first one - ip multicast address appears on enp0s3

# ip -4 maddr show dev enp0s3
2:  enp0s3
    inet  224.0.0.251  <===== 
    inet  224.0.0.1

the second one, "systemd-resolved" starts listening the socket * UDP 5353

# lsof -n -P -p $(pidof systemd-resolved) | grep UDP | grep 5353
   UDP *:5353 
   UDP *:5353 

Everithyng is ready.
Now you can make mdns queries by using systemd-resolved via general dns clients:

# resolvectl query debian12-c2.local
debian12-c2.local: 172.16.10.12                -- link: enp0s3

or

# dig -4 @127.0.0.53  debian12-c2.local
..  
..  
;; ANSWER SECTION:
debian12-c2.local.  80  IN  A   172.16.10.12

or

# getent ahostsv4 debian12-c2.local
172.16.10.12    STREAM debian12-c2.local

As for my knowledge, it is not possible to set systemd-resolved to work in mdns client-only mode. It works in mdns client+server mode or doesnt work at all.

Alex
  • 148