Post

ENG | Zero-config DNS: Exploring the AVAHI Daemon

Delve into the AVAHI daemon, facilitating seamless hostname resolution via Multicast DNS (mDNS) without manual configuration.

ENG | Zero-config DNS: Exploring the AVAHI Daemon

Introduction

Have you ever wondered how domain names like fedora.local are resolved effortlessly, without explicit configuration? This is the realm of Multicast DNS (mDNS) and AVAHI daemon.

Understanding AVAHI

Most Linux distributions ship with the AVAHI daemon pre-installed. It silently responds to mDNS requests, providing the hostname for all network interfaces. This robust mechanism ensures seamless hostname resolution, regardless of the active network connection (WiFi or Ethernet), as long as the .local domain is used.

Addressing Exceptions (Debian)

AVAHI daemon is not universally present. For instance, minimal Debian installs do not include AVAHI pre-installed. To check if it’s running, you can use systemctl status avahi-daemon or ps axuw|grep avahi. If it’s absent, manual installation is required:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
pavel@stoat:~$ su -
Password:
root@stoat:~# apt install avahi-daemon
⋮
root@stoat:~# systemctl status avahi-daemon.service
● avahi-daemon.service - Avahi mDNS/DNS-SD Stack
     Loaded: loaded (/lib/systemd/system/avahi-daemon.service; enabled; preset: enabled)
     Active: active (running) since Tue 2023-07-11 21:22:38 CEST; 1min 5s ago
⋮
root@stoat:~# ping stoat.local
PING stoat.local (192.168.0.199) 56(84) bytes of data.
⋮
root@stoat:~# ping marten.local
PING marten.local (192.168.0.143) 56(84) bytes of data.
⋮

Don’t forget to restart AVAHI after updating the hostname (e.g., hostnamectl set-hostname new-hostname) to reflect changes.

Windows Support

While not natively supported, Windows can act as an mDNS client by enabling multicast DNS.

Open command prompt with administrator privileges. Copy and paste this command:

1
reg add "HKLM\Software\Policies\Microsoft\Windows NT\DNSClient" /v EnableMulticast /t REG_DWORD /d 1 /f

It uses IPv6 by default, but it works, at least as a client.

1
2
3
4
PS C:\Users\pavel> ping marten.local

Pinging marten.local [fe80::e62c:bcea:e88f:40d5%7] with 32 bytes of data:
⋮

Summary

The AVAHI daemon and mDNS play crucial roles in simplifying hostname resolution and enhancing network communication robustness. While often overlooked, understanding AVAHI’s role can provide valuable insights for better network setup navigation and troubleshooting of your network setup.

First, I used AVAHI for convenience. Then I found it almost necesseary in situations that need to locate device without doing IP scan of a whole subnet. Some of these use cases are:

  • Connecting to Raspberry PI from a notebook when both are assigned dynamic IP address from a mobile hotspot.
  • Connecting to a host OS from podman/docker/lxc container, when I don’t know what IP address was assigned to the host (and host may be connected either to wifi or by cable)

Troubleshooting

Some distros (openSUSE) may not have enabled mDNS in firewall.

1
2
3
4
5
6
7
8
9
10
11
12
pavel@suse:~> ping marten.local
ping: marten.local: Name or service not known
pavel@suse:~> sudo firewall-cmd --list-services
[sudo] password for root:
dhcpv6-client
pavel@suse:~> sudo firewall-cmd --add-service=mdns --permanent
success
pavel@suse:~> ping marten.local
PING marten.local (fe80::e62c:bcea:e88f:40d5%wlo1) 56 data bytes
64 bytes from marten.local (fe80::e62c:bcea:e88f:40d5%wlo1): icmp_seq=1 ttl=64 time=5.40 ms
64 bytes from marten.local (fe80::e62c:bcea:e88f:40d5%wlo1): icmp_seq=2 ttl=64 time=1.64 ms
⋮

Changelog

  • 2024-05-29: Practical use cases in summary
  • 2024-06-01: Added openSUSE troubleshooting

Reference

This post is licensed under CC BY 4.0 by the author.