For the complete documentation index, see llms.txt. This page is also available as Markdown.

37.4 Zero-Configuration Networking (mDNS/DNS-SD)

Zero-configuration networking (Zero-configuration networking, also known as Zeroconf) is a set of technologies that simplify network configuration, enabling network devices to automatically complete address assignment, domain name resolution, and service discovery without administrator intervention.

This functionality is particularly useful on embedded devices. In some scenarios, users cannot obtain the IP address of a Raspberry Pi through a screen or serial port but need to connect via SSH. Raspberry Pi OS enables the Avahi service by default and supports multicast DNS. In this case, users can directly use ping raspberrypi.local to obtain the IP address, or connect directly via SSH to raspberrypi.local.

The main components of zero-configuration networking include:

Component
English Name
Description

Link-Local Addressing

Link-Local Addressing

Provides automatic assignment of numeric network addresses

Multicast DNS

mDNS

Provides automatic distribution and resolution of hostnames

DNS-Based Service Discovery

DNS-SD

Provides automatic discovery of service instances

A common implementation of Zeroconf is Avahi. nss-mdns enables all tools that use nsswitch (The Name Service Switch, NSS) to look up hostnames with the *.local suffix via the mDNS protocol.

Installing Avahi and nss-mdns

Install using pkg:

# pkg install avahi-app nss_mdns

Install using Ports:

# cd /usr/ports/net/avahi-app/ && make install clean
# cd /usr/ports/dns/nss_mdns/ && make install clean

Configuring the Name Service Switch

dns/nss_mdns installs the following NSS modules:

lib/nss_mdns.so.1
lib/nss_mdns_minimal.so.1
lib/nss_mdns4.so.1
lib/nss_mdns4_minimal.so.1
lib/nss_mdns6.so.1
lib/nss_mdns6_minimal.so.1
lib/nss_mdns.so
lib/nss_mdns_minimal.so
lib/nss_mdns4.so
lib/nss_mdns4_minimal.so
lib/nss_mdns6.so
lib/nss_mdns6_minimal.so

For descriptions of the above modules, see avahi/nss-mdns.

The /etc/nsswitch.conf file is the nsswitch configuration file, with source code located at lib/libc/net/nsswitch.conf. The default file content is as follows:

To enable mDNS, append mdns and mdns6 after the hosts: files dns line.

Enabling Services

D-Bus is automatically installed as a dependency of Avahi. Set it to start automatically at boot:

Start the D-Bus service:

Set the Avahi daemon to start automatically at boot:

Start the Avahi service:

Testing the Service

Execute the ping command to test the FreeBSD hostname, which will display the IP address.

Tip

The ykla and ykla.local in the above example are placeholders and need to be replaced with actual values.

You can also view the IPv6 address:

This matches the actual IP address of the FreeBSD host, confirming the configuration is correct.

Connect to the device using SSH:

Tip

The username ykla and hostname ykla shown in the examples in this section are for demonstration purposes. Please replace them with the actual username and hostname for your environment.

Last updated