My raspberry pi server hostname doesn't work?

5,082

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.

Share:
5,082

Related videos on Youtube

xSpartanCx
Author by

xSpartanCx

Updated on September 18, 2022

Comments

  • xSpartanCx
    xSpartanCx over 1 year

    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.

    • mikołak
      mikołak almost 11 years
      Do you have a DNS server set up?
    • xSpartanCx
      xSpartanCx almost 11 years
      Uh, I'm not sure... How would I know?
    • mikołak
      mikołak almost 11 years
      You probably don't then :). Writing up the answer.
    • xSpartanCx
      xSpartanCx almost 11 years
      In /etc/resolv.conf i have "nameserver 192.168.1.1" if that helps any
  • xSpartanCx
    xSpartanCx almost 11 years
    The reason I had the other server was so I could run two websites. This is what my /etc/apache2/httpd.conf file looks like on the other server:pastebin.com/x67Fa4Ci
  • xSpartanCx
    xSpartanCx almost 11 years
    Also, my other server "piston"'s hostname showed up on the router, and it worked with putty
  • xSpartanCx
    xSpartanCx almost 11 years
    and this is my /etc/network/interfaces: pastebin.com/kq96vjfm
  • xSpartanCx
    xSpartanCx almost 11 years
    But the problem is, now that I turned off my other server, nothing works on the Pi
  • Craig
    Craig almost 11 years
    The hostname is sent to the dhcp server when the Raspbery Pi requests an IP address. If the dhcp server supports it (and is also handling your network's DNS) it will add the hostname to the local domain and then using the hostname will work.
  • mikołak
    mikołak almost 11 years
    OK... will you be using the other server again? If not, just follow the steps in the answer, if so, "reverse" the config it is the Pi that is configured in virtual hosts and its httpd.conf redirects requests to the other server for the desired paths. Unless you set up a DNS server (which also has to be somewhere), one or the other has to run all the time either way for this to work.
  • xSpartanCx
    xSpartanCx almost 11 years
    Okay, I've come to terms with not being able to get my hostname to work :) but my main problem is my website not working. When I restart apache, this warning shows up:"could not reliably determine the server's fully qualified, domain name, using 127.0.1.1 for ServerName" my problem is, the setup worked fine with the other server on, and i specifically made no changes to the Pi so that it would work when I turned off the server. But now that it is off, the Pi doesn't work and I don't know why...+
  • mikołak
    mikołak almost 11 years
    That's solvable, but it's out of scope of your original question (the comments are long enough as they are). I suggest searching the net, and if you can't find a solution, ask a separate question (probably on ServerFault instead).
  • xSpartanCx
    xSpartanCx almost 11 years
    A ha! I solved my problem. What turns out is that i forwarded port 80 to my other server, so that way it could distribute to my Pi. So all I had to do was change the forward to my Pi.