11

Often (maybe 80% of the time), when I reboot a machine running Avahi, it starts using machinename-2.local as it's hostname. All the machines on my network have unique hostnames, so there is no collision.

How do I prevent Avahi from appending -2 to hostnames?

(This turns out to be an incredibly difficult thing to Google for...)

dty
  • 263
  • 2
  • 12
  • 1
    Did you find a solution? In my case I have an apple macbook on the same network and two raspberry pis running with avahi-daemon and one of those RPis generates this conflict – ffleandro Mar 24 '21 at 14:59
  • @ffleandro Just wanted to join on to that "Did you find a solution?" (I started getting the problem with a simple normal install of ubuntu 20.04 desktop, about a week after setting it up.) – Owen_AR Apr 01 '21 at 17:05
  • 1
    I haven' found a solution yet. Do you have more than one avahi server in the same network? Found this ticket on the project, but it is still open. There is already a PR open but hasn't been merge: https://github.com/lathiat/avahi/issues/117 – ffleandro Apr 02 '21 at 13:54

3 Answers3

2

This is also the case with OS X machines.

If the hostname is already in use on the network it bumps the counter to make the names unique again. I would suspect that the machine in question may have two netcards to the same network (cabled and wireless) or that you have a bonjour proxy running (which may be unknown to you) which helps sleeping machines by holding their hostname active. To be more certain you may want to describe your network better.

2

In my case, this behavior is caused by a Plex Media Server inside a docker container which runs its own avahi-daemon. I'm using this docker image: https://hub.docker.com/r/linuxserver/plex/

The number was increased very often, without need to restart.

After stopping the docker container and a restart of avahi-daemon.service, the numbers disappeared.

Powerriegel
  • 333
  • 1
  • 6
  • 15
1

I have the same problem on a Raspberry Pi. Until a better solution comes along, Ive added a crontab entry to run this script every day.

#!/bin/bash

writelog()
{
echo $(date) >> /home/pi/avahirestart.log
}
aname=$(avahi-resolve -a $(hostname -I|cut -d' ' -f1)|cut -f2)
if [[ "$aname" = *"-2"* ]];then
sudo service avahi-daemon restart
writelog
fi
if [[ "$aname" = *"-3"* ]];then
sudo service avahi-daemon restart
writelog
fi
Ken H
  • 111
  • 4