Configuring avahi-daemon on Raspberry Pi
avahi raspberry-pi docker mdnsI’ve been having intermittent issues connecting to my Raspberry Pi using the local domain name interwebs.local
. After the most recent issue, I decided to actually figure out the root cause.
The problem #
I went to check the grafana dashboard on my pi today at http://interwebs.local:3000
and got the dreaded This site cannot be reached
message. That’s not good, especially since this website is running on the pi. A quick check showed that the site was still up and running (whew!) and I was able to reach the pi by ip address.
Since the pi was still up and responding, I figured the most likely culprit was mDNS. I did a quick scan of the system logs in /var/log/syslog
and was able to find the problem:
avahi-daemon[324]: Host name conflict, retrying with interwebs-2
So it looks like the avahi-daemon thinks the interwebs
name already exists so it just adds a -2
to the name when registering the address. Checking this in the browser with http://interwebs-2.local:3000
does indeed bring up the grafana dashboard.
The solution #
It turns out this is a known bug in avahi: Spurious name conflicts · Issue #117 · lathiat/avahi · GitHub While it’s not fixed yet, it does look like there are two possible workarounds that we can try: limit the interfaces avahi interacts with and avoid IPv6 if you can.
Let’s start with specifying the interfaces. We can take a look at what interfaces are available with this command:
ip link | awk 'NR % 2 == 1 {print substr($2, 1, length($2)-1)}'
And the results look something like this:
lo
eth0
wlan0
docker0
br-97ab6ddb7319
veth236375f@if6
vetha16ca98@if8
veth1400258@if10
veth77d9a14@if12
veth7087693@if14
vethdb6a27c@if16
tun0
That’s a lot of interfaces, with the majority of them belonging to docker. In fact, any time a docker container starts or stops it creates/tears down an interface which causes avahi to register or withdraw a record. That means more chances for the bug to happen. The only interface we really care about is eth0
. We can tell avahi to only listen on that interface in the config file /etc/avahi/avahi-daemon.conf
. Add this line:
allow-interfaces=eth0
On my local network, I don’t really need IPv6 either so let’s disable that as well. By default, IPv6 is enabled with this line in /etc/avahi/avahi-daemon.conf
:
use-ipv6=yes
We have to change that setting to no
, and we also need to update the publish settings:
use-ipv6=no
publish-a-on-ipv6=no
publish-aaaa-on-ipv4=no
Restart the service with
sudo systemctl restart avahi-daemon
Restarting the daemon has fixed the issue, and interwebs.local
is accessible again. Checking the logs, it appears to only be listening on eth0
, and only on IPv4. When starting and stopping a docker container, I see the network interfaces getting created and destroyed in the logs, but now avahi does not try to advertise on those interfaces.
So far I have not seen any issues with this setup, but time will tell if this does actually fix the issue.