2

I have an application which has an mDNS server running on an ESP32 device. Its hostname is esp32-mdns.local. I can ping this hostname from Windows. However, it is not possible from my Ubuntu 22.04 system.

I have re-installed the avahi daemon and the utils again. When I do avahi-browse --all :

avahi-browse -all
+ wlp0s20f3 IPv6 192-168-178-1                                 Microsoft Windows Network local
+ wlp0s20f3 IPv6 fritz-box                                     Microsoft Windows Network local
+ wlp0s20f3 IPv4 192-168-178-1                                 Microsoft Windows Network local
+ wlp0s20f3 IPv4 fritz-box                                     Microsoft Windows Network local
+ wlp0s20f3 IPv6 ESP32-WebServer1                              Web Site             local
+ wlp0s20f3 IPv6 ESP32-WebServer                               Web Site             local
+ wlp0s20f3 IPv4 ESP32-WebServer1                              Web Site             local
+ wlp0s20f3 IPv4 ESP32-WebServer                               Web Site             local

Then avahi-resolve --name esp32-mdns.local :

avahi-resolve --name esp32-mdns.local
esp32-mdns.local    192.168.178.71

So, the name is getting resolved, but when I ping it :

ping esp32-mdns.local
ping: esp32-mdns.local: Name or service not known

I can ping the IP address directly, but not the hostname.

Here is my /etc/avahi/avahi-daemon.conf file. Am I missing something? Or what could be the issue? Thanks.

# avahi is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with avahi; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA.

# See avahi-daemon.conf(5) for more information on this configuration
# file!

[server]
#host-name=foo
#domain-name=local
#browse-domains=0pointer.de, zeroconf.org
use-ipv4=yes
use-ipv6=yes
#allow-interfaces=eth0
#deny-interfaces=eth1
#check-response-ttl=no
#use-iff-running=no
#enable-dbus=yes
#disallow-other-stacks=no
#allow-point-to-point=no
#cache-entries-max=4096
#clients-max=4096
#objects-per-client-max=1024
#entries-per-entry-group-max=32
ratelimit-interval-usec=1000000
ratelimit-burst=1000

[wide-area]
enable-wide-area=yes

[publish]
#disable-publishing=no
#disable-user-service-publishing=no

1 Answer 1

5

You need the libnss_mdns_minimal.so library installed (from the "libnss-mdns" package) and configured in /etc/nsswitch.conf so that the system would know to talk to Avahi-daemon for looking up hostnames.

Ubuntu's packaging will likely enable it automatically (or will enable the IPv4-only 'mdns4'; you can then edit nsswitch.conf to change to the dual-stack variant). If it is not automatically enabled, add

mdns_minimal [NOTFOUND=return]

to the hosts: line of /etc/nsswitch.conf, after the files module – but before dns or resolve. For example:

hosts: files mdns_minimal [NOTFOUND=return] dns

Many recent distributions instead have partial mDNS support as part of the resolve module from systemd-resolved; you can use that instead – although when I tried it the last time, it insisted on doing mDNS reverse queries for IPv6 causing every reverse lookup to take exceedingly long (not to mention it conflicting with avahi-daemon for inbound queries, so it is generally better to not mix the two).

(That is, if you have a program that relies on Avahi's DNS-SD service discovery API, then stick to Avahi. Whereas if you only need *.local hostname lookup and nothing else, then you can use either Avahi or systemd-resolved, but not both of them.)


In the case of systemd-resolved, the nsswitch.conf module is called resolve – the same module handles both DNS and mDNS – and it should be listed in the same position (but in this case you can omit dns, though it's common to include it as emergency fallback):

hosts: files resolve
 -or-
hosts: files resolve dns

resolved's mDNS support needs to be enabled either via /etc/systemd/resolved.conf or via individual systemd-networkd connection profiles as the MulticastDNS= option, or via Network­Manager connection profiles as the connection.mdns option. (You don't need to do any of this for Avahi.)

The combination of both Avahi for mDNS and systemd-resolved for regular DNS would look like:

hosts: files mdns_minimal [NOTFOUND=return] resolve
 -or-
hosts: files mdns_minimal [NOTFOUND=return] resolve dns
6
  • Thank you for this. The only thing that worked for me was changing the line in /etc/nsswitch.conf to hosts: files mdns_minimal [NOTFOUND=return] dns and doing a reboot. I experimented with resolved also but no joy. I notice now that each ping response takes around 5 seconds, when pinging the hostname. Is there a way to make this faster? Commented Dec 17, 2024 at 10:39
  • That might be avahi being asked to resolve the address back to hostname (i.e. the same kind of problem as I mentioned systemd-resolved having) and waiting the whole 5 seconds for a reply that never arrives. Does mdns4_minimal work any better? If not, then fire up Wireshark and see what kind of requests it's sending... Commented Dec 17, 2024 at 10:45
  • Ah yes, mdns4_minimal does ion fact work much better. Now i'm confused though as mdns4_minimal was the default setting which didn't work initially, but now does. However, I did disable IPV6 in /etc/avahi/avahi-daemon.conf Commented Dec 17, 2024 at 11:14
  • I tried this and I also disabled IPv6, but it did not work. See also Commented Mar 13 at 20:51
  • Also see this question Commented Mar 13 at 22:34

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.