Linux – My raspberry pi server hostname doesn’t work

linuxnetworkingraspberry pi

The people over on the rPi forums don't have any answers for me…

I've got a raspberry pi running raspbian server edition. My problem is that the only way I can ssh into it with putty is through the static ip.

My router doesn't recognize the hostname; it shows the mac address as the name. This causes the pi not to show my apache2 website online (I think). The only way I've gotten it to work is using my other linux server to forward using virtual hosts, and that has to use the ip address, too.

However, now that I have my other server off, the website doesn't work.

Best Answer

The hostname for your server is for the purpose of IP resolution local to your Pi. The router won't recognize it automatically.

The network protocol which is used for network communication does not use domain/host names, just MAC addresses - the former are mostly for the convenience of us humans.

Unless you have a router that actively queries hostnames from the machines set up on your LAN (haven't seen such a thing myself), your router recognizes devices by their MACs.

Your best bet is to simply:

  1. Set up a static IP for your Pi's MAC (if you haven't already).
  2. Set up the virtual host port forwarding to your Pi directly on your router (most should handle that, so that you don't need to use your other machine for this purpose).

You could set up a DNS server on your Pi, such as bind9, which would map your hostname to your IP address, but that requires a lot of configuration, and would only work on the computers that recognize that DNS server anyway (so computers/servers that you have specifically set up for this).

If you want to refer to your Pi using it's hostname from your desktop/laptop, add the hostname/IP number pair to your computer's hosts file.

Related Question