My raspberry pi server hostname doesn't work?

2

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.

xSpartanCx

Posted 2013-07-02T20:31:40.677

Reputation: 23

2Do you have a DNS server set up? – mikołak – 2013-07-02T21:19:43.677

Uh, I'm not sure... How would I know? – xSpartanCx – 2013-07-02T21:30:00.430

1You probably don't then :). Writing up the answer. – mikołak – 2013-07-02T21:30:58.410

In /etc/resolv.conf i have "nameserver 192.168.1.1" if that helps any – xSpartanCx – 2013-07-02T21:40:57.067

Answers

2

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.

mikołak

Posted 2013-07-02T20:31:40.677

Reputation: 254

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:http://pastebin.com/x67Fa4Ci

– xSpartanCx – 2013-07-02T21:48:03.203

Also, my other server "piston"'s hostname showed up on the router, and it worked with putty – xSpartanCx – 2013-07-02T21:53:48.260

Your router queried your Pi for the hostname, that's why it showed up on the list. And Putty recognizing it is just its feature apparently, the ssh client I have installed on my Linux box does no such thing. I would say that your best bet is to stick with your current Apache config, optionally adding the hostname/IP pair to your "main" server's /etc/hosts file, so that you can use your Pi's hostname in httpd.conf. – mikołak – 2013-07-02T22:02:55.970

and this is my /etc/network/interfaces: http://pastebin.com/kq96vjfm

– xSpartanCx – 2013-07-02T22:04:06.357

But the problem is, now that I turned off my other server, nothing works on the Pi – xSpartanCx – 2013-07-02T22:11:01.277

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. – Craig – 2013-07-02T22:16:11.393

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. – mikołak – 2013-07-02T22:19:51.723

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...+ – xSpartanCx – 2013-07-02T22:20:20.300

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). – mikołak – 2013-07-02T22:22:47.563

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. – xSpartanCx – 2013-07-02T22:40:38.060