Avahi Hostname Resolution: Is it caching somewhere?

13.8k views Asked by At

I am using Fedora 18 with the avahi command line tools (version 0.6.31)

I use avahi-resolve-host-name to discover the IP address of units on my subnet, for testing purposes during development. I monitor the request and response with Wireshark. After one successful request and response, no further requests show up on Wireshark, but the tool still returns an IP address. Is it possible the computer/avahi daemon/something else is 'caching' the result?

The Question: I wish to send out the request packet with EVERY CALL of avahi-resolve-host-name. Is this possible?

The Reason: I'm getting 'false positives' so to speak. I try to resolve 'test1.local', and I am getting a resulting IP, but the unit is no longer located at this IP. I want the request sent every time so I can avoid seeing units at incorrect IP addresses.

2

There are 2 answers

0
ja2142 On

I just stumbled upon this problem myself and found solution that doesn't require changing the config. It seems that simply killing the daemon (avahi-daemon --kill) flushes the cache. I'm on Ubuntu 18.04 and the daemon is restarted automatically. If on some other distro it isn't running after being killed, it can be restarted with avahi-daemon --daemonize.

Note that root is needed to kill avahi daemon, so this might not be the best option in some cases.

2
Michał Górny On

I see that I'm a bit late to answer your question but I'm going to leave a generic answer in case someone else stumbles upon this.

My answer is based on avahi-0.6.32_rc.


Is it possible the computer/avahi daemon/something else is 'caching' the result?

Yes, avahi-daemon is caching lookup results. While this doesn't seem to be explicitly listed in features, the avahi-daemon(8) manpage tips it:

The daemon [...] provides two IPC APIs for local programs to make use of the mDNS record cache the avahi-daemon maintains.


I wish to send out the request packet with EVERY CALL of avahi-resolve-host-name. Is this possible?

Yes, it is. The relevant option is cache-entries-max (from avahi-daemon.conf(5)):

cache-entries-max= Takes an unsigned integer specifying how many resource records are cached per interface. Bigger values allow mDNS work correctly in large LANs but also increase memory consumption.

To achieve the desired effect, you can simply set:

cache-entries-max=0

This will disable the caching entirely and force avahi-daemon to reissue the MDNS packets on every request, therefore making it possible for you to monitor them.

However, I should note here that this will also render avahi pretty much useless for normal use. While avahi-daemon will be issuing lookup packets, it will be unable to store the results and every call of avahi-resolve-host-name (as well as other command-line tools, nss-mdns, D-Bus API…) will fail.