7

I want to ssh into my Pi and I can do it right now with the ip address of the Pi. But I want to do it using mDNS. I want to connect using ssh raspberrypi.local. I read that this should work. on the pi, the avahi-deamon is running:

pi@raspberrypi:~ $ service avahi-daemon status
● avahi-daemon.service - Avahi mDNS/DNS-SD Stack
   Loaded: loaded (/lib/systemd/system/avahi-daemon.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2020-09-28 12:01:52 CEST; 35min ago
 Main PID: 326 (avahi-daemon)
   Status: "avahi-daemon 0.7 starting up."
    Tasks: 2 (limit: 1915)
   CGroup: /system.slice/avahi-daemon.service
           ├─326 avahi-daemon: running [raspberrypi.local]
           └─379 avahi-daemon: chroot helper

Sep 28 12:31:21 raspberrypi avahi-daemon[326]: Interface eth0.IPv6 no longer relevant for mDNS.
Sep 28 12:31:21 raspberrypi avahi-daemon[326]: Withdrawing address record for 10.42.0.56 on eth0.
Sep 28 12:31:21 raspberrypi avahi-daemon[326]: Leaving mDNS multicast group on interface eth0.IPv4 with address 10.42.0.56.
Sep 28 12:31:21 raspberrypi avahi-daemon[326]: Interface eth0.IPv4 no longer relevant for mDNS.
Sep 28 12:31:34 raspberrypi avahi-daemon[326]: Joining mDNS multicast group on interface eth0.IPv6 with address fe80::a3a0:c51a:4fa:5bd0.
Sep 28 12:31:34 raspberrypi avahi-daemon[326]: New relevant interface eth0.IPv6 for mDNS.
Sep 28 12:31:34 raspberrypi avahi-daemon[326]: Registering new address record for fe80::a3a0:c51a:4fa:5bd0 on eth0.*.
Sep 28 12:31:45 raspberrypi avahi-daemon[326]: Joining mDNS multicast group on interface eth0.IPv4 with address 10.42.0.56.
Sep 28 12:31:45 raspberrypi avahi-daemon[326]: New relevant interface eth0.IPv4 for mDNS.
Sep 28 12:31:45 raspberrypi avahi-daemon[326]: Registering new address record for 10.42.0.56 on eth0.IPv4.

The hostname is also raspberrypi so that is not the issue. I think the issue might be in my linux system I use to connect to the pi?

If I try to connect this is the error:

➜  ~ ssh raspberrypi.local
ssh: Could not resolve hostname raspberrypi.local: Name or service not known

avahi-browse -arp and avahi-resolve-host-name both also do not work.

My linux system is Fedora 32. I have checked that Avahi is running (same command as on the pi).

I connected the raspberry pi with an ethernet cable to my computer (which is using WiFi). I am sharing my WiFi to my Pi by setting the wired connection to "Shared to other computers" (with both IPv4 and IPv6).

Here is the avahi config on the pi:

pi@raspberrypi:~ $ cat /etc/avahi/avahi-daemon.conf 
# This file is part of avahi.
#
# avahi is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# 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
#add-service-cookie=no
#publish-addresses=yes
publish-hinfo=no
publish-workstation=no
#publish-domain=yes
#publish-dns-servers=192.168.50.1, 192.168.50.2
#publish-resolv-conf-dns-servers=yes
#publish-aaaa-on-ipv4=yes
#publish-a-on-ipv6=no

[reflector]
#enable-reflector=no
#reflect-ipv=no

[rlimits]
#rlimit-as=
#rlimit-core=0
#rlimit-data=8388608
#rlimit-fsize=0
#rlimit-nofile=768
#rlimit-stack=8388608
#rlimit-nproc=3

I am not sure why my system is not able to find the Pi... If you need any more information, I'll be glad to provide!

2
  • What is the ip address and netmask of the device where try to connect to the RasPi?
    – Ingo
    Commented Sep 30, 2020 at 17:02
  • seems like mdns/avahi works by default on bookworm even in the minimal distribution Commented Mar 19 at 12:34

4 Answers 4

4

In the avahi.conf:

#allow-interfaces=eth0  

Needs to have the # removed, restart the avahi service, and that fixed it for me.

3
  • 1
    allow-interfaces defaults to all local interfaces except loopback and point-to-point (ref) so this shouldn't make any difference. But in any case the output from service avahi-daemon status will show you which interfaces avahi is using.
    – kthy
    Commented Feb 11, 2022 at 8:42
  • 1
    @kthy I found your response helpful and "service avahi-daemon status" showed me I had an error while the daemon was running. "avahi-daemon[445]: No service file found in /etc/avahi/services." I did two things, uncommented "allow-interfaces=eth0" and added modified and uncommented "host-name=raspberrypi". Thanks!
    – Ron K.
    Commented Feb 10, 2023 at 16:22
  • 2
    I also had to modify "enable-wide-area=no" for the error messages to go away. Track the output of the service with "sudo journalctl -fu avahi-daemon.service" which will tail the log for you. Thanks!
    – Ron K.
    Commented Feb 10, 2023 at 16:52
1

You may have to amend the config file for the GNU Name Service Switch at /etc/nsswitch.conf to include mdns4_minimal when resolving domain names.

In my case (Ubuntu 20.04 + KDE):

  • I had this: hosts: files dns
  • I changed it to: hosts: files dns mdns4_minimal

After the change above I was able to do ssh [email protected] and successfully log into my Raspberry Pi without using a dynamic IP (e.g. something assigned via DHCP by the router to my Raspberry Pi).

See for reference:

1
  • 1
    I unfortunately already have mdns4_minimal in my conf file. However, I have fixed the issue by connecting my pi directly to my router instead of sharing WiFi through an ethernet cable with the pi. Commented Oct 5, 2020 at 15:04
1

For avahi-daemon to broadcast the presence of a device on the network you need to tell it to publish something.

change: publish-workstation=no to publish-workstation=yes then:

systemctl avahi-daemon restart
1
  • publish-workstation=yes just registers a service of type _workstation._tcp on the local LAN (ref). What you need is actually publish-domain=yes which is the default.
    – kthy
    Commented Feb 11, 2022 at 8:33
0

You have been over thinking this and/or confused by posts about Zero-conf

From most OS (with the exception of some Windows) you can resolve the name raspberrypi.local e.g with ping raspberrypi.local.

To connect via ssh you need to use the correct commands e.g. ssh [email protected] for a normal Raspberry Pi OS.

NOTE Occasionally this will fail, due to caching in the network, but this is unusual.

1
  • The ping and ssh both do not work as I said... I accidentally forgot the user indeed for the ssh but it doesn’t change anything sadly. Commented Sep 29, 2020 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.