Finding network services via mDNS

mDNS lets us announce own network services as well as discover other services on the network. It also allows to store bookmarks of services that still work when the IP of the device changed.

On Linux, the Avahi daemon and cli tools can be used.

Discovery

Scan for all services on the network:

avahi-browse --all
+ enx00000000b000 IPv4 sybo                          Remote Disk Management local
+ enx00000000b000 IPv4 dm7080                        SFTP File Transfer   local
+ enx00000000b000 IPv4 DM7080                        Microsoft Windows Network local
+ enx00000000b000 IPv4 dm7080                        SSH Remote Terminal  local
+ enx00000000b000 IPv4 digira                        _spotify-connect._tcp local
+ enx00000000b000 IPv4 disa [00:11:32:02:23:42]      Workstation          local
+ enx00000000b000 IPv4 Schwibb__gen f__r HomeApp     _simplehome._tcp     local
+ enx00000000b000 IPv4 shellyplus1-a8032abd1d94      _shelly._tcp         local
+ enx00000000b000 IPv4 disa                          Web site             local

Columns:

  1. Status (+ or =)
  2. Network interface (enx00000000b000)
  3. IP type (4 or 6)
  4. Service name ("sybo")
  5. Service type ("Remote Disk Management")
  6. Domain ("local")

There are many different services listed; some of them have nice names like "Remote Disk Management". To see the underlying service keys use --no-db-lookup:

avahi-browse --all --no-db-lookup
+ enx00000000b000 IPv4 sybo                          _udisks-ssh._tcp     local
+ enx00000000b000 IPv4 dm7080                        _sftp-ssh._tcp       local

All official registered keys can be found in the Service Name and Transport Protocol Port Number Registry.

--parsable gives us the escaped UTF-8 characters instead of _ (I have a service "Schwibbögen für HomeApp"):

+;enx00000000b000;IPv4;disa\032\09100\05811\05832\05802\05860\0589f\093;Arbeitsplatzrechner;local
+;enx00000000b000;IPv4;Schwibb\195\182gen\032f\195\188r\032HomeApp;_simplehome._tcp;local

IP resolution

To get the IP address for a service, combine the service name with the domain. Separate them with a dot and call avahi-resolve:

$ avahi-resolve --name sybo.local
sybo.local	192.168.3.4

This does unfortunately not work when there are UTF-8 characters in the service name, which seems to be a bug in avahi 0.8:

$ avahi-resolve --name "Schwibb\195\182gen\032f\195\188r\032HomeApp.local"
Failed to resolve host name 'Schwibb\195\182gen\032f\195\188r\032HomeApp.local': Timeout reached

A workaround is to use avahi-browse for resolution, too:

$ avahi-browse --parsable --resolve _simplehome._tcp
+;enx00000000b000;IPv4;Schwibb\195\182gen\032f\195\188r\032HomeApp;_simplehome._tcp;local
=;enx00000000b000;IPv4;Schwibb\195\182gen\032f\195\188r\032HomeApp;_simplehome._tcp;local;dojo.local;192.168.3.3;80;"url=http://simpleapi-homeapp.home.cweiske.de/"

This also gives us the TXT records.

Applications using mDNS

Epiphany (Gnome Web) browser had Zeroconf bookmarks until 2016 but not anymore.

avahi-discover

GUI shipped with Avahi.

system-config-printer

Mate's printer configuration tool searches for network printers by querying for this services:

Vinagre

The Gnome desktop VNC/SSH viewer automatically scans for services and puts them in the bookmarks menu:

Written by Christian Weiske.

Comments? Please send an e-mail.