1

I am using a Raspberry Pi Zero 2W for some development, and am having trouble with headless operation through SSH.

The usual method is via "ssh user@raspberrypi.local". This is on and off functional for me, and I often have to resort to connecting a monitor etc. to find the IP address.

The error when ".local" doesn't work is "ssh: Could not resolve hostname ccp.local: name or service not known".

I have found this guide about using Bonjour and Avahi, which I implemented at least a year ago, and still get the exact same problem here and there.

I have also tried this and this guide regarding setting up ssh over USB, then attempting ssh via both command line and PuTTY, which again results in the above error when using command prompt, and the error "Unable to open connection to raspberrypi.local. Host does not exist".

Using the IP address instead of raspberypi.local seems to always work, but the intended use case for the pi is rather reliant on headless being functional upon startup.

Does anyone know why this is so unreliable?

  • Feels like raspberry unrelated question and should be asked in networking community. Have you tried to check if the issue affects other hosts in your network? Are there other Pis in your network? – Vadim Apr 10 '23 at 18:28

3 Answers3

0

This happens occasionally. The .local resolution works by sending a broadcast message.

The problem is not with the Pi (it affects other devices) and appears to be related to address caching.

The only reliable solution is to restart the router and occasionally the target device.

arp probing can explore the issue and may resolve it.

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • This is at an office that I believe has several repeaters or access points, and has occurred over the course of at least a year, likely a year and a half in varying degrees.

    Is arp probing then a good method of finding the IP of the connected RPI?

    Thanks for the tip though, I'll certainly give it a try.

    – Daniel Godø-Dempsey Apr 14 '23 at 09:48
0

My experience has been mostly similar to Milliways. However, I have found that one thing seems to help:

Your hostname is stored in /etc/hostname; in my case /etc/hostname contains the following:

$ less /etc/hostname
raspberrypi3b

Make sure that the file /etc/hosts contains at least this reference to 127.0.1.1 as the final entry:

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters
127.0.1.1       raspberrypi3b.local

Note that you can add additional hostnames here, so I always put this in for the final line of /etc/hosts:

...
127.0.1.1       raspberrypi3b.local raspberrypi3b

I've found that this gives me more reliable name resolution under avahi.

Seamus
  • 21,900
  • 3
  • 33
  • 70
  • Had a look at the hosts file, and it seems like it's identical to your example, save that the last line is "127.0.1.1 raspberrypi" rather than "127.0.1.1 raspberrypi.local", if that is of any significance?

    In any case I have appended it as suggested and will give that a try.

    – Daniel Godø-Dempsey Apr 14 '23 at 10:02
  • @DanielGodø-Dempsey: It might be significant; the 127.0.1.1 bit is unique to Debian-based distros AFAIK, and the documentation is not entirely clear. It seems to have helped in my case. – Seamus Apr 15 '23 at 00:30
0

In addition to the suggestions by other commenters, I found a thread discussing what seemed to be a fairly similar problem, where installing the package called "Samba" was suggested for Windows users. This solved the immediate issue for me.

Here is the thread I found.