LinuxInSchoolGuide/HostnameResolution
2024-09-12 09:17:03 +02:00
..
README.md Initial commit 2024-09-12 09:17:03 +02:00

Setting up Hostname resolution

Dynamic hostname resolution in modern linux distributions is provided by Avahi.

Installation

Refer to the documentation for your linux distribution. The following instructions are for arch linux, but the process should be roughly the same on other distributions as well.

sudo pacman -S avahi

Then enable the service. Here you can choose between enabling the service or using socket activation.

A. Socket activation: avahi will only be started when a program or service requests it.

sudo systemctl enable avahi-daemon.socket

B. Enabling the service: avahi will always be active, even when no service has requested it.

`sudo systemctl enable --now avahi-daemon.service

systemd-resolved might conflict with avahi. You can manually go through its config and disable the multicast DNS resolver/responder, or you can disable the service entirely:

sudo systemctl disable systemd-resolved

You also need the following package:

sudo pacman -S nss-mdns

Configuration

Edit the file /etc/nsswitch.conf and change the hosts line to include mdns_minimal [NOTFOUND=return] before resolve and dns.

Here is an example:

hosts: mymachines mdns_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] files myhostname dns

If you experience slowdowns in resolving .local hosts (or you do not want to use IPv6) try to use mdns4_minimal and mdns4 instead of mdns_minimal and mdns respectively.

Fix issue with NSS-MDNS caused by systemd-resolved

If you didn't disable systemd-resolved entirely, and instead only disabled multicast DNS resolution, please follow this step. If you disabled the service entirely you can skip this.

First, make sure you have the host command available on your system. On arch linux, it is installed by the bind package in the extra repository.

sudo pacman -S bind

Then, run the following command and hope that it returns NXDOMAIN:

host -t SOA local

If the host did respond with NXDOMAIN, you don't need to follow the rest of the steps in this section.

If it didn't, continue reading.

Replace mdns_minimal in /etc/nsswitch.conf that you added earlier, with the full mdns module:

hosts: mymachines mdns [NOTFOUND=return] resolve [!UNAVAIL=return] files myhostname dns

And then create /etc/mdns.allow with the following content:

.local.
.local

Note that this solution might break reverse lookups, such as traceroute. To fix this, change back mdns to mdns_minimal. This will unfortunately sacrifice your dynamic hostname resolution ability.

Other than that, you are done.