44

How can I disable avahi-daemon and can you explain to me how it runs if it appears as a service but it itsn't in rcN.d?


You can stop reading here. In fact, please do unless you want to TEACH a noob some Ubuntu. The question above should be clear enough to be answered. The rest is just me calling out for some more structured way of finding one's way around Ubuntu. I can more or less use other "UNIX-like" systems.

I am a beginner so if I act nonsensically, consider me your daily WTF but do help me improve, please.

At every boot, /sbin/init seems to be launching a process called avahi-daemon

# initctl list | grep avahi
avahi-daemon start/running, process 1280

as user avahi

# id avahi
uid=107(avahi) gid=118(avahi) groups=118(avahi)

a ps -efww ef shows 2 processes active, both called avahi-daemon, and the PPID of the first avahi-daemon is indeed 1, the second process is just a child of the first. The PPID = 1 is what makes me think this was auto-started.


Optionally:

I don't really know how to check properly what gets executed at system startup, thinking about it.

Is this the way to get a list of services that run at startup? initctl list | sort


anyway, I seem to be able to temporarily stop this "service" through this command:

service avahi-daemon stop

or indeed this command

/etc/init.d/avahi-daemon stop

directly, which is what this /usr/sbin/service seems to be using:

env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE"

When launched, the script reminds me that I am controlling an "Upstart" service, and that I should use the simpler invocation stop avahi-daemon. I guess I will need to learn about Upstart but for now, all I need to learn is this:

how do I disable services in Ubuntu?

Here is what I tried (this should be the proper way to do it, or is it not?):

update-rc.d avahi-daemon disable

but it complains:

System start/stop links for /etc/init.d/avahi-daemon do not exist

so I went hunting for the path to the binary:

# Let me know if there is a better way to get the path above
readlink "/proc/$(echo `ps --no-headers -o pid -C avahi-daemon | head -n 1`)/exe"

which is this:

/usr/sbin/avahi-daemon

and anything that could be considered an "executable file" in etc:

find /etc -type f -name '*avahi*' -perm -u+x

thinking I would find startup scripts in /etc/rcN.d. I found other things instead:

/etc/dhcp/dhclient-exit-hooks.d/zzz_avahi-autoipd
/etc/dhcp/dhclient-enter-hooks.d/avahi-autoipd
/etc/resolvconf/update-libc.d/avahi-daemon
/etc/network/if-up.d/avahi-autoipd
/etc/network/if-up.d/avahi-daemon
/etc/network/if-down.d/avahi-autoipd
/etc/avahi/avahi-autoipd.action

seems like this avahi-daemon thing is being launched on network state changes? Is there a better way to hunt down binaries automatically started on a system?

I would have normally obliterated the symlinks in the various rc{3,5}.d at this stage but now I am not too sure. What exactly starts this beast? How to disable it without apt-get remove or apt-get purge?

It does not have too many resources open, as far as I can see:

lsof -p $(echo `ps --no-headers -o pid -C avahi-daemon | head -n 1`)

nor does it use too many CPU cycles, based on a quick glance at htop.

I wrote this one-liner to see if it goes funky on CPU util over a period of one minute, and it never does, but let me know if there are better ways to check that:

for i in {1..59}; do ps -p $(echo `ps --no-headers -o pid -C avahi-daemon | head -n 1`) --no-headers -o pcpu; sleep 1; done
1
  • 9
    A for effort!
    – Geoff
    Dec 10, 2013 at 21:27

9 Answers 9

28
sudo systemctl disable avahi-daemon

worked for me on Ubuntu Gnome 15.10

1
  • 2
    You can also run "sudo systemctl stop avahi-daemon" to stop it immediately. This is the real answer to the question.
    – EnzoR
    Feb 25, 2018 at 18:44
23

Upstart startup scripts live in /etc/init, where you can find avahi-daemon.conf. All things listed in initctl list match to scripts in /etc/init, and they are not executable, thus your find missed them.

To disable a Upstart controlled service, see Upstart cookbook on disabling services: either add # to start on line, or use override files (example: sudo sh -c "echo manual > /etc/init/avahi-daemon.override").

2
  • or comment out the whole start on stanza, to be technical. I commented out three lines, for example.
    – noobninja
    Jan 19, 2018 at 16:06
  • Its better to use service avahi-daemon stop Mar 13, 2019 at 17:05
11

I found that even if I stop avahi-daemon (and avahi-daemon.socket), Firefox always restarts it. However, this works, and disables this annoying daemon permanently:

apt-get remove avahi-daemon
6
  • What does firefox have anything to do with this question?
    – Mxx
    Oct 15, 2016 at 14:48
  • 2
    @Mxx firefox just triggers the socket which restarts Avahi. I had to uninstall it as well in order to make wget and curl not use it.
    – qwertzguy
    Feb 7, 2017 at 0:12
  • drastic solution, but fast and working one!
    – andilabs
    Sep 6, 2017 at 13:43
  • Read all answers, considered this one a joke, tried the other ones to no avail, finally used this one and upvoted it
    – golimar
    Nov 5, 2019 at 8:54
  • And to be completely thorough, sudo DEBIAN_FRONTEND=noninteractive apt-get purge --auto-remove avahi-daemon
    – volvox
    Jun 6, 2020 at 20:16
5

You might not need to stop it from starting up when PC boots, but maybe prevent it from respawn as it does, when you kill it.

So, just comment out the respawn in /etc/init/avahi-daemon.conf

Killing that process always failed, so couldn't get airmon-ng check to pass. Commenting out the respawning, it kills and never comes back hunting me.

1
  • I don't have the respawn line on my raspbian :< Nov 9, 2021 at 15:08
4

You need to mask the socket to prevent applications starting avahi-daemon:

systemctl mask avahi-daemon.socket
systemctl disable avahi-daemon
systemctl stop avahi-daemon
1
  • airmon-ng never stop conplaining.. until I masked the service. Good call Nov 9, 2021 at 15:08
1

service avahi-daemon stop

Use this. Works wonders.

Then use airmon-ng check wlo1 to check overlapping services. U should find none.

1
  • Works once. Next time you boot avahi starts again. Is this what you want? No I think, because question was how to disable avahi (to start). use above mentioned 'sudo systemctl disable avahi-daemon' to disable avahi without removing it or 'sudo apt-get remove avahi-daemon' to remove avahi permanently, so it can't start. May 31, 2021 at 17:14
0

How about using

sysv-rc-conf

For these thing? It's very handy!

(i.e. first install it with apt-get and then run it as sudo)

0

Just used this and works fine on Ubuntu 16.04

service avahi-daemon stop


I know the OP uses this line, but to summarize for who is searching for a simple command (like myself).

0

Just purge it. Or disable it in rc3.d, rc4.d , and rc5.d So as su / root

apt-get purge avahi-daemon

yes

Than it should be off your system. Check your /etc/rc3.d and others and it should be gone from startup.

Don't use systemd for disable best way is to remove or change the runscript to K instead of S in the run layers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .