52

My Raspberry Pi is not discoverable via its hostname in my LAN.

I have a couple of other Ubuntu machines in the LAN, and they are all pingable via their hostnames.

On my Raspberry Pi:

pi@raspberrypi ~ $ hostname
raspberrypi

On another machine in the same LAN:

ping raspberrypi
ping: unknown host raspberrypi
Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
clamp
  • 829
  • 2
  • 12
  • 19
  • Duplicate question: http://unix.stackexchange.com/questions/77189/debian-not-reachable-via-its-hostname-in-lan. Closed as off-topic as this is a general Linux networking issue, not related to the Raspberry Pi. – Jivings Jun 07 '13 at 06:54
  • 1
    Why is it not releated to Raspberry Pi if I have an Odroid with Ubuntu 14.04, a MÎNIX with Debian and a virtual PC I boot with Ubuntu 15.10 in the same network without this issue? Only on my Raspberry Pi 2 with Raspian I have this issue since I upgraded to Jessie. –  Jan 18 '16 at 14:24
  • just as a side note, this will probably not affect most people out there reading this, but some people might have avahi installed and wondering why it's not working for them -> one possibility is that your network configuration doesn't support multicast. – Lukas1 Jul 04 '16 at 05:41
  • @clamp Shouldn't it be ping raspberrypi.local, I think that the .local part is vital – Linus Unnebäck Jan 22 '18 at 11:00

2 Answers2

81

You have to use avahi-daemon (zeroconf) if you want to connect via a hostname instead of an IP address. From the Raspberry Pi documentation on RPi Advanced Setup:

Install avahi with the following commands on the Raspberry Pi:

sudo apt-get install avahi-daemon

Update boot startup for avahi-daemon

sudo insserv avahi-daemon

Apply the new configuration with:

sudo /etc/init.d/avahi-daemon restart

The Raspberry Pi should now be addressable from other machines as raspberrypi.local, for example: ssh pi@raspberrypi.local or http://raspberrypi.local if you have HTTP service installed.

If you couldn't connect from Windows PCs via SSH probably you haven't installed the Bonjour service.

Get Bonjour for Windows: Download Bonjour Print Services for Windows v2.0.2. Just install it.

Peter Mortensen
  • 2,004
  • 2
  • 15
  • 18
gurcanozturk
  • 3,748
  • 1
  • 19
  • 17
  • 14
    This should be the selected answer – Sudar Aug 10 '13 at 15:43
  • 3
    Silly, just to let others know: in my case my home router (Pirelli Centro Grande) is handling dhcp for my LAN. I never had ssh or network issues with Raspian nor any other Linux in my LAN until I upgraded to Raspian Jessie. This automatically installed dhcpd and avahi. I had to remove both, avahi-daemon and isc-dhcpd-server to avoid dhcp and name server conflicts with my router. Now my Raspberry is available by its name again. –  Jan 18 '16 at 16:16
  • 1
    I had the same issue as @ShyRobbiani - disabling/removing avahi-daemon caused my rpi to be picked up on my home network as it did pre-Jessie. – keithl8041 Jan 01 '17 at 18:54
  • Why does this just work on retropie? https://github.com/RetroPie/RetroPie-Setup/wiki/SSH – dashnick Oct 11 '17 at 03:49
  • 4
    'insserv' isn't available on my raspbian... ? – oo_dev Oct 18 '17 at 15:01
  • 6
    @copa017 Not here either on my Raspbian Lite at least, but just sudo apt-get install insserv. Otherwise follow the instructions above. Tested and worked for me! – Jonas Dec 26 '17 at 19:53
  • 2
    $ sudo insserv avahi-daemon insserv: FATAL: service mountkernfs has to exists for service udev insserv: FATAL: service mountdevsubfs has to exists for service hwclock insserv: FATAL: service urandom has to exists for service networking insserv: FATAL: service udev is missed in the runlevels 2 3 4 5 to use service raspi-config insserv: exiting now! – JeanCarlos Chavarria May 30 '21 at 00:42
19

Have you tried doing a ping test using the IP address? If that works your problem is usually with resolving the name to an IP address.

There are many ways to fix this. You could

  • Add an entry to your /etc/hosts file with your pi's static-ip and hostname
  • Add a static reservation to your dhcp server and add a record to your local dns server (If your router supports it)
  • Run a service like NIS, Avahi or Samba on your pi. The choice depends on the OS you are pinging from.
    • Windows clients will benefit from installing Samba.
    • OS/X clients will benefit from Avahi or Samba.
    • Linux clients will probably benefit from NIS or Samba depending on what is installed. I guess the Ubuntu computers use samba to advertise their hostnames.
  • yeah pinging via the ip is fine, but it does not have a static ip address. – clamp May 26 '13 at 21:20
  • What OS are you pinging the pi and ubuntu boxes from? If you are on a linux machine could you see what the value of hosts: is in your /etc/nsswitch.conf? – Surajram Kumaravel May 26 '13 at 21:22
  • 2
    Thanks. I've solved mine via Samba. Samba will be useful at some point as its a bit easier to access files this way – fedmich Mar 14 '16 at 16:02