Multicast DNS is a protocol that is normally used for the discovery of printers. It is implemented by Avahi, but more setup is needed for the regular name resolution to see the results.
Install, enable and start avahi with:
It should now be possible to browse results. To look for a printer, use:
Make note of the hostname, as we will use it afterwards.
Name resolution is implemented by musl, and it only supports DNS, so we have to map the avahi results to a regular DNS server. This is done by avahi2dns.
since we will want a full DNS server running at port 53, we need to configure avahi2dns to use another port. Do that by creating /etc/conf.d/avahi2dns containing:
Enable and start avahi2dns with
It should now be possible to use DNS to query the address of the printer.
Where printer_name is the hostname given by avahi-browse.
Setup DNS resolver
We now need to setup a DNS resolver that will forward request of .local domain to avahi2dns and handle other requests normally. There is more than one way to do it, but we document an option that is probably most convenient for a laptop: using the DHCP provided server for the regular DNS requests. We will use unbound as the server and resolvconf to inform unbound about the DHCP results.
Install the programs:
This tells resolveconf to use a local nameserver and pass the DHCP provided DNS server to unbound
forward-zone: name: "local" forward-addr: 127.0.0.1@5354 include: "/etc/unbound-resolvconf.conf" server: do-not-query-localhost: no domain-insecure: "local"
This reads the information provided by resolvconf, but forwards .local requests to avahi2dns. We also need to disable dnssec for .local and tell unbound that it is OK to query localhost.
Enable and start unbound
Setup DHCP client
How send the DHCP provided DNS to resolvconf depends on the DHCP client being used.
This is the DHCP client in busybox, and will work for both wired and wireless interfaces.
#!/bin/sh cat /etc/udhcpc-resolv.conf | resolvconf -a $interface
An inconvenience of this setup is that udhcpc will not reconfigure the interface when connecting to other wifi networks. For that to happen one has to run
To avoid having to manually reconfigure the wifi interface, we can configure iwd to use DHCP internally and forward DNS server info to resolveconf. To do that create /etc/iwd/main.conf:
Test the setup
You should now be able to query for both the printer address and regular addresses with
Your /etc/resolv.conf should also contain
Printer discovery should now be working.