My raspberry pi server hostname doesn't work?
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:
- Set up a static IP for your Pi's MAC (if you haven't already).
- 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 videos on Youtube
xSpartanCx
Updated on September 18, 2022Comments
-
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 almost 11 yearsDo you have a DNS server set up?
-
xSpartanCx almost 11 yearsUh, I'm not sure... How would I know?
-
mikołak almost 11 yearsYou probably don't then :). Writing up the answer.
-
xSpartanCx almost 11 yearsIn /etc/resolv.conf i have "nameserver 192.168.1.1" if that helps any
-
-
xSpartanCx almost 11 yearsThe 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 almost 11 yearsAlso, my other server "piston"'s hostname showed up on the router, and it worked with putty
-
xSpartanCx almost 11 yearsand this is my /etc/network/interfaces: pastebin.com/kq96vjfm
-
xSpartanCx almost 11 yearsBut the problem is, now that I turned off my other server, nothing works on the Pi
-
Craig almost 11 yearsThe 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 almost 11 yearsOK... 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 almost 11 yearsOkay, 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 almost 11 yearsThat'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 almost 11 yearsA 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.