MDNS: Difference between revisions

From Alpine Linux
m (→‎Setup avahi: doas is the preferred elevation method in Alpine. Used cmd template.)
m (→‎Setup avahi2dns: Use various templates, doas instead of sudo, and minor grammar improvements.)
Line 18: Line 18:
== Setup avahi2dns ==
== Setup avahi2dns ==


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.
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.


  git clone https://github.com/LouisBrunner/avahi2dns
{{cmd|git clone https://github.com/LouisBrunner/avahi2dns
  cd avahi2dns
cd avahi2dns
  go build
go build
  sudo cp avahi2dns /usr/bin
doas cp avahi2dns /usr/bin
  sudo cp openrc/avahi2dns /etc/init.d
doas cp openrc/avahi2dns /etc/init.d}}


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
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 {{path|/etc/conf.d/avahi2dns}} containing:


   command_args="-p 5354"
   command_args="-p 5354"
Line 32: Line 32:
Enable and start avahi2dns with
Enable and start avahi2dns with


sudo rc-update add avahi-daemon
{{cmd|doas rc-update add avahi-daemon
sudo rc-service avahi-daemon start
doas rc-service avahi-daemon start}}


It should now be possible to use dns to query the address of the printer.
It should now be possible to use DNS to query the address of the printer.


  drill -p 5354 @127.0.0.1 <printer_name>.local
{{cmd|drill -p 5354 @127.0.0.1 <printer_name>.local}}


Where printer_name is the hostname given by avahi-browse.
Where printer_name is the hostname given by avahi-browse.


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 and iwd to inform unbound about the dhcp results.
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 and iwd to inform unbound about the DHCP results.


Install the programs:
Install the programs:


  apk add openresolv unbound iwd
{{cmd|doas apk add openresolv unbound iwd}}


Create /etc/resolvconf.conf:
Create {{path|/etc/resolvconf.conf}}:


   name_servers=127.0.0.1
   name_servers=127.0.0.1
   unbound_conf=/etc/unbound-resolvconf.conf
   unbound_conf=/etc/unbound-resolvconf.conf


This tells resolveconf to use a local nameserver and pass the dhcp provided dns server to unbound
This tells resolveconf to use a local nameserver and pass the DHCP provided DNS server to unbound


Create /etc/unbound/unbound.conf:
Create {{path|/etc/unbound/unbound.conf}}:


   forward-zone:
   forward-zone:
Line 66: Line 66:
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.
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.


And the last config charge is to have iwd forward dns server info to resolveconf. To do that create /etc/iwd/main.conf:
And the last config charge is to have iwd forward DNS server info to resolveconf. To do that create {{path|/etc/iwd/main.conf}}:


   [Network]
   [Network]
Line 73: Line 73:
Enable and start unbound
Enable and start unbound


  sudo rc-update add unbound
{{cmd|doas rc-update add unbound
  sudo rc-service unbound
doas rc-service unbound}}


Reconnect to your wifi. You should now be able to query for both the printer address and regular addresses with
Reconnect to your wifi. You should now be able to query for both the printer address and regular addresses with


  drill @127.0.0.1 <printer_name>.local
{{cmd|drill @127.0.0.1 <printer_name>.local
  drill @127.0.0.1 alpinelinux.org
drill @127.0.0.1 alpinelinux.org}}


Your /etc/resolv.conf should also contain
Your {{path|/etc/resolv.conf}} should also contain


   nameserver 127.0.0.1
   nameserver 127.0.0.1


So printer discovery should now be working.
Printer discovery should now be working.

Revision as of 08:14, 19 December 2023

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.

Setup avahi

Install, enable and start avahi with:

doas apk add avahi doas rc-update add avahi-daemon doas rc-service avahi-daemon start

It should now be possible to browse results. To look for a printer, use:

doas apk add avahi-tools avahi-browse --resolve --terminate _ipp._tcp

Make note of the hostname, as we will use it afterwards.

Setup avahi2dns

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.

git clone https://github.com/LouisBrunner/avahi2dns cd avahi2dns go build doas cp avahi2dns /usr/bin doas cp openrc/avahi2dns /etc/init.d

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:

 command_args="-p 5354"

Enable and start avahi2dns with

doas rc-update add avahi-daemon doas rc-service avahi-daemon start

It should now be possible to use DNS to query the address of the printer.

drill -p 5354 @127.0.0.1 <printer_name>.local

Where printer_name is the hostname given by avahi-browse.

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 and iwd to inform unbound about the DHCP results.

Install the programs:

doas apk add openresolv unbound iwd

Create /etc/resolvconf.conf:

 name_servers=127.0.0.1
 unbound_conf=/etc/unbound-resolvconf.conf

This tells resolveconf to use a local nameserver and pass the DHCP provided DNS server to unbound

Create /etc/unbound/unbound.conf:

 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.

And the last config charge is to have iwd forward DNS server info to resolveconf. To do that create /etc/iwd/main.conf:

 [Network]
 NameResolvingService=resolvconf

Enable and start unbound

doas rc-update add unbound doas rc-service unbound

Reconnect to your wifi. You should now be able to query for both the printer address and regular addresses with

drill @127.0.0.1 <printer_name>.local drill @127.0.0.1 alpinelinux.org

Your /etc/resolv.conf should also contain

 nameserver 127.0.0.1

Printer discovery should now be working.