1

I've got a Raspberry Pi Zero V1.2 that is plugged into a powered USB hub that in turn is plugged into my router via Ethernet cable. (Basically like this.)

On my desktop computer, running Arch Linux, when I try running ssh pi@raspberrypi to connect to the Pi, I get this error: ssh: Could not resolve hostname raspberrypi: Name or service not known.

On the Pi, when I run hostname or cat /etc/hostname, the output is raspberrypi.

And here's the output of cat /etc/hosts:

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

127.0.1.1 raspberrypi

On my Arch Linux computer, I can connect to the Pi Zero using its IP address on my network by running ssh pi@192.168.1.7.

What must I do to SSH into my Pi using its hostname too?

update

The output of cat /etc/hosts on my Arch machine is this...

# Static table lookup for hostnames.
# See hosts(5) for details.
Username
  • 83
  • 1
  • 7

2 Answers2

2

Make sure your hostname files are setup correctly on BOTH ends:

Pi /etc/hosts:

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

127.0.1.1 raspberrypi

Arch (SSH Client) /etc/hosts:

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

[Pi WLAN/LAN IP] raspberrypi

Your Pi is likely to be 192.168.0.[something] or 10.0.1.[something]

This is only particularly useful if you have a static IP for your Pi.

What I recommend instead of Hostnames for SSH...

Is using the ~/.ssh/config file:

In the ~/.ssh/config file:

host RasPi
    user pi
    hostname 192.168.0.[Pi IP]

This will be more useful for the purpose of SSH, and it much more useful (in my opinion) when you start to do more fancy things with SSH (Proxy jump, Port Forward, Local/External IP matching)

Another thing that I have seen:

Some people recommend using Bonjour for Hostname resolution. So you can look into that if you want Hostname resolution on WLAN/LAN.

Hope this helps!

Awbmilne
  • 126
  • 1
  • 5
-1

The normal (i.e. non Windows) operation of Zero-conf uses the .local "domain".

This is a function of your local network and source computer as Raspberry Pi OS has Zero-conf enabled by default.

Occasionally caching prevents Zero-conf resolution and the only cure I have found is to restart all network devices although pinging sometimes refreshes the arp cache.

Try raspberrypi.local

Milliways
  • 62,573
  • 32
  • 113
  • 225