Use avahi/mDNS to advertise your Pi-hole's services to network clients

mDNS (multicast DNS) is distinct from DNS. It allows devices across a network to get information about available services without requiring any configuration input from the user. It was originally designed by Apple as the core of their Bonjour zero-configuration system, but it is now widely used across operating systems and devices. In parallel with DHCP (or in some cases instead of DHCP), some devices are able to obtain information such as available dns and ntp servers via mDNS.

The avahi service is the most common way of providing mDNS functionality under linux. It can advertise the services provided by your Pi-hole to any devices that make use of mDNS to locate them.

Avahi is installed by default on most distros, and is probably already running on the system running Pi-Hole. To test if avahi is installed and active on the system running Pi-hole, ssh in and type pgrep avahi-daemon -l.
image
If it lists one or more process numbers, followed by 'avahi-daemon', then it is active.

The files necessary to have avahi permanently advertise services are typically located in /etc/avahi/services.

To advertise your Pi-hole's DNS server, create the file /etc/avahi/services/domain.service
image
with the following contents:

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">

<service-group>

  <name replace-wildcards="yes">%h</name>

  <service protocol="any">
    <type>_domain._udp</type>
    <port>53</port>
  </service>

</service-group>

Similarly, to advertise Pi-hole's NTP server, create /etc/avahi/services/ntp.service
image
with the following contents:

<?xml version="1.0" standalone='no'?><!--*-nxml-*-->
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">

<service-group>

  <name replace-wildcards="yes">%h</name>

  <service protocol="any">
    <type>_ntp._udp</type>
    <port>123</port>
  </service>

</service-group>

The avahi-daemon will detect the files being written and update its information automatically, there is no need to restart it.

(Note that if Pi-hole is set to be listening only on its ipv4 address, then <service protocol="all"> should be changed to to <service protocol="ipv4"> in the above files).

4 Likes