Use the Avahi mDNS/DNS-SD daemon to identify services on Raspberry Pi devices.
Ensure that Avahi daemon and utilities are installed.
$ sudo apt install avahi-daemon avahi-utils
Ensure that .local
will work as expected.
$ cat /etc/nsswitch.conf
# /etc/nsswitch.conf # # Example configuration of GNU Name Service Switch functionality. # If you have the `glibc-doc-reference' and `info' packages installed, try: # `info libc "Name Service Switch"' for information about this file. passwd: files group: files shadow: files gshadow: files hosts: files mdns4_minimal [NOTFOUND=return] dns networks: files protocols: db files services: db files ethers: db files rpc: db files netgroup: nis
Inspect default Avahi daemon configuration.
$ cat /etc/avahi/avahi-daemon.conf
# This file is part of avahi. # # avahi is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # avahi is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public # License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with avahi; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA. # See avahi-daemon.conf(5) for more information on this configuration # file! [server] #host-name=foo #domain-name=local #browse-domains=0pointer.de, zeroconf.org use-ipv4=yes use-ipv6=yes #allow-interfaces=eth0 #deny-interfaces=eth1 #check-response-ttl=no #use-iff-running=no #enable-dbus=yes #disallow-other-stacks=no #allow-point-to-point=no #cache-entries-max=4096 #clients-max=4096 #objects-per-client-max=1024 #entries-per-entry-group-max=32 ratelimit-interval-usec=1000000 ratelimit-burst=1000 [wide-area] enable-wide-area=yes [publish] #disable-publishing=no #disable-user-service-publishing=no #add-service-cookie=no #publish-addresses=yes publish-hinfo=no publish-workstation=no #publish-domain=yes #publish-dns-servers=192.168.50.1, 192.168.50.2 #publish-resolv-conf-dns-servers=yes #publish-aaaa-on-ipv4=yes #publish-a-on-ipv6=no [reflector] #enable-reflector=no #reflect-ipv=no #reflect-filters=_airplay._tcp.local,_raop._tcp.local [rlimits] #rlimit-as= #rlimit-core=0 #rlimit-data=8388608 #rlimit-fsize=0 #rlimit-nofile=768 #rlimit-stack=8388608 #rlimit-nproc=3
Alter it to disable IPv6 and use LAN interface.
$ cat /etc/avahi/avahi-daemon.conf
# This file is part of avahi. # # avahi is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # avahi is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public # License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with avahi; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 # USA. # See avahi-daemon.conf(5) for more information on this configuration # file! [server] #host-name=foo #domain-name=local #browse-domains=0pointer.de, zeroconf.org use-ipv4=yes use-ipv6=no allow-interfaces=eth0 #deny-interfaces=eth1 #check-response-ttl=no #use-iff-running=no #enable-dbus=yes #disallow-other-stacks=no #allow-point-to-point=no #cache-entries-max=4096 #clients-max=4096 #objects-per-client-max=1024 #entries-per-entry-group-max=32 ratelimit-interval-usec=1000000 ratelimit-burst=1000 [wide-area] enable-wide-area=yes [publish] #disable-publishing=no #disable-user-service-publishing=no #add-service-cookie=no #publish-addresses=yes publish-hinfo=no publish-workstation=no #publish-domain=yes #publish-dns-servers=192.168.50.1, 192.168.50.2 #publish-resolv-conf-dns-servers=yes #publish-aaaa-on-ipv4=yes #publish-a-on-ipv6=no [reflector] #enable-reflector=no #reflect-ipv=no #reflect-filters=_airplay._tcp.local,_raop._tcp.local [rlimits] #rlimit-as= #rlimit-core=0 #rlimit-data=8388608 #rlimit-fsize=0 #rlimit-nofile=768 #rlimit-stack=8388608 #rlimit-nproc=3
Inspect SSH service definition.
$ cat /usr/share/doc/avahi-daemon/examples/ssh.service
<?xml version="1.0" standalone='no'?><!--*-nxml-*--> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <!-- This file is part of avahi. avahi is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. avahi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. --> <!-- See avahi.service(5) for more information about this configuration file --> <service-group> <name replace-wildcards="yes">%h</name> <service> <type>_ssh._tcp</type> <port>22</port> </service>
Copy service definition.
$ sudo cp /usr/share/doc/avahi-daemon/examples/ssh.service /etc/avahi/services/
Create sample Pi-hole service definition.
$ sudo tee /etc/avahi/services/pi-hole.service <<EOF <service-group> <name replace-wildcards="yes">Pi-hole DNS on %h</name> <service> <type>_domain._udp</type> <port>53</port> </service> <service> <type>_domain._tcp</type> <port>53</port> </service> <service> <type>_http._tcp</type> <port>80</port> <txt-record value-format="text">ext_url=http://pi-hole.example.org/admin/</txt-record> </service> </service-group> EOF
Create sample Nextcloud service definition.
$ sudo tee /etc/avahi/services/nextcloud.service <<EOF <service-group> <name replace-wildcards="yes">Nextcloud on %h</name> <service> <type>_https._tcp</type> <port>443</port> <txt-record value-format="text">ext_url=https://nextcloud.example.org</txt-record> </service> </service-group> EOF
Create sample location service.
$ sudo tee /etc/avahi/services/location.service <<EOF <service-group> <name replace-wildcards="yes">Location of %h</name> <service> <type>_home-sharing._tcp</type> <txt-record value-format="text">rack=02</txt-record> </service> </service-group> EOF
Reload Avahi daemon configuration.
$ sudo avahi-daemon --reload
Display all discovered services.
$ avahi-browse --all --terminate
+ eth0 IPv4 Home Assistant _home-assistant._tcp local + eth0 IPv4 Nextcloud on raspberrypi-2 Secure Web Site local + eth0 IPv4 Pi-hole DNS on raspberrypi-1 DNS Server local + eth0 IPv4 Pi-hole DNS on raspberrypi-1 _domain._tcp local + eth0 IPv4 Pi-hole DNS on raspberrypi-1 Web Site local + eth0 IPv4 raspberrypi-2 SSH Remote Terminal local + eth0 IPv4 raspberrypi-1 SSH Remote Terminal local + eth0 IPv4 Location of raspberrypi-2 Apple Home Sharing local + eth0 IPv4 Location of raspberrypi-1 Apple Home Sharing local + eth0 IPv4 _workstation _tcp local + eth0 IPv4 _services _dns-sd._udp local + eth0 IPv4 _home-assistant _tcp local + eth0 IPv4 _https _tcp local + eth0 IPv4 _domain _udp local + eth0 IPv4 _domain _tcp local + eth0 IPv4 _http _tcp local + eth0 IPv4 _ssh _tcp local + eth0 IPv4 _home-sharing _tcp local + eth0 IPv4 homeassistant [861bb367ed424d97b414966cd0bfb9f5] Workstation local
Display all discovered services with additional details.
$ avahi-browse --all --terminate --resolve
+ eth0 IPv4 Home Assistant _home-assistant._tcp local + eth0 IPv4 Nextcloud on raspberrypi-2 Secure Web Site local + eth0 IPv4 Pi-hole DNS on raspberrypi-1 DNS Server local + eth0 IPv4 Pi-hole DNS on raspberrypi-1 _domain._tcp local + eth0 IPv4 Pi-hole DNS on raspberrypi-1 Web Site local + eth0 IPv4 raspberrypi-2 SSH Remote Terminal local + eth0 IPv4 raspberrypi-1 SSH Remote Terminal local + eth0 IPv4 Location of raspberrypi-2 Apple Home Sharing local + eth0 IPv4 Location of raspberrypi-1 Apple Home Sharing local + eth0 IPv4 _workstation _tcp local + eth0 IPv4 _services _dns-sd._udp local + eth0 IPv4 _home-assistant _tcp local + eth0 IPv4 _https _tcp local + eth0 IPv4 _domain _udp local + eth0 IPv4 _domain _tcp local + eth0 IPv4 _http _tcp local + eth0 IPv4 _ssh _tcp local + eth0 IPv4 _home-sharing _tcp local = eth0 IPv4 Pi-hole DNS on raspberrypi-1 DNS Server local hostname = [raspberrypi-1.local] address = [192.168.8.170] port = [53] txt = [] = eth0 IPv4 Location of raspberrypi-1 Apple Home Sharing local hostname = [raspberrypi-1.local] address = [192.168.8.170] port = [0] txt = ["rack=02"] = eth0 IPv4 Pi-hole DNS on raspberrypi-1 _domain._tcp local hostname = [raspberrypi-1.local] address = [fe80::511c:62ce:1b9:bf2f] port = [53] txt = [] = eth0 IPv4 raspberrypi-1 SSH Remote Terminal local hostname = [raspberrypi-1.local] address = [192.168.8.170] port = [22] txt = [] = eth0 IPv4 Pi-hole DNS on raspberrypi-1 Web Site local hostname = [raspberrypi-1.local] address = [192.168.8.170] port = [80] txt = ["ext_url=http://pi-hole.example.org/admin/"] = eth0 IPv4 Nextcloud on raspberrypi-2 Secure Web Site local hostname = [raspberrypi-2.local] address = [192.168.8.165] port = [443] txt = ["ext_url=https://nextcloud.example.org"] = eth0 IPv4 Location of raspberrypi-2 Apple Home Sharing local hostname = [raspberrypi-2.local] address = [192.168.8.165] port = [0] txt = ["rack=01"] = eth0 IPv4 raspberrypi-2 SSH Remote Terminal local hostname = [raspberrypi-2.local] address = [192.168.8.165] port = [22] txt = [] = eth0 IPv4 Home Assistant _home-assistant._tcp local hostname = [f298974bbd0a45e5898d5c466f4ae8b9.local] address = [192.168.8.172] port = [8123] txt = ["requires_api_password=True" "base_url=http://192.168.8.172:8123" "internal_url=http://192.168.8.172:8123" "external_url=" "version=2022.12.8" "uuid=f298974bbd0a45e5898d5c466f4ae8b9" "location_name=Home Assistant"] + eth0 IPv4 homeassistant [861bb367ed424d97b414966cd0bfb9f5] Workstation local = eth0 IPv4 homeassistant [861bb367ed424d97b414966cd0bfb9f5] Workstation local hostname = [homeassistant.local] address = [192.168.8.172] port = [0] txt = []
Display all discovered services, but skip current server.
milosz@raspberrypi-1:~ $ avahi-browse --all --ignore-local --terminate
+ eth0 IPv4 homeassistant [861bb367ed424d97b414966cd0bfb9f5] Workstation local + eth0 IPv4 _workstation _tcp local + eth0 IPv4 _services _dns-sd._udp local + eth0 IPv4 _home-assistant _tcp local + eth0 IPv4 _https _tcp local + eth0 IPv4 _domain _udp local + eth0 IPv4 _domain _tcp local + eth0 IPv4 _http _tcp local + eth0 IPv4 _ssh _tcp local + eth0 IPv4 _home-sharing _tcp local + eth0 IPv4 Home Assistant _home-assistant._tcp local + eth0 IPv4 Nextcloud on raspberrypi-2 Secure Web Site local + eth0 IPv4 raspberrypi-2 SSH Remote Terminal local + eth0 IPv4 Location of raspberrypi-2 Apple Home Sharing local
Search for specific service.
$ avahi-browse --terminate _ssh._tcp
+ eth0 IPv4 raspberrypi-2 SSH Remote Terminal local + eth0 IPv4 raspberrypi-1 SSH Remote Terminal local
Search for specific service and display additional services.
$ avahi-browse --terminate --resolve _https._tcp
+ eth0 IPv4 Nextcloud on raspberrypi-2 Secure Web Site local = eth0 IPv4 Nextcloud on raspberrypi-2 Secure Web Site local hostname = [raspberrypi-2.local] address = [192.168.8.165] port = [443] txt = ["ext_url=https://nextcloud.example.org"]
Search for specific hostname.
$ avahi-resolve-host-name -4 --name raspberrypi-1.local
raspberrypi-1.local 192.168.8.170
Search for specific IP address.
$ avahi-resolve-host-name -4 --address 192.168.8.165
192.168.8.165 raspberrypi-2.local
Additional notes
Inspect list of defined DNS SRV (RFC 2782) Service Types.