Page 1 of 1

Hostname web server problem

Posted: Mon Aug 20, 2012 1:06 pm
by GuitarTater
I'm new to this forum so this is probably the wrong place (sorry :( )

I'm looking to set up a little web server on my home network for website development and so I can teach myself a little bit about web hosting and how to optimise sites etc...

The problem I have at the minute is connecting using the hostname of the raspberry pi. There's a couple of tutorials I have followed that are basically the same steps.

I've enabled SSH and I can use PuTTY to remotely control the Pi but only using the local IP address
I've tried to change the hostname by editing /etc/hosts and /etc/hostname, as well as just hostname xxxxxxxx

For some reason I can't connect to it with the new hostname (or the old one), have I made an error in the Pi side of things or is it likely to be a router problem?

Any help would be greatly appreciated
Thanks :)

The tutorials I used are and ... /?ALLSTEPS

Re: Hostname web server problem

Posted: Mon Aug 20, 2012 2:33 pm
by M.M
Hi GuitarTater,

could you recheck if your hostname is configured correctly by just typing "hostname" in a terminal?

Did you use spaces? If you did, I think your hostname will be cut off at the first space.

If the shown hostname is correct, you can be sure that the RasPi itself knows its name ;)

But to connect to it, the machine you use to establish your ssh session needs to be able to match the name to an IP address, too.

Since you use PuTTy I am guessing you are using Windows?

So, could you please open a cmd window and check if your computer can reach your Pi by its hostname by executing "ping <hostname>"?

This should narrow down were we would have to look for the problem.


Re: Hostname web server problem

Posted: Mon Aug 20, 2012 6:52 pm
by GuitarTater
Hi M.M
Thanks for your response :)

The Pi appears to know it's own name when type hostname in the terminal. Yes I'm using Windows, pinging the hostname doesn't work it just says "ping request could not find host xxxx".

I have noticed that when I login to the Pi, when it asks for the password it says enter Password for (the ip address of the Pi), but when i've logged in the terminal says pi@"hostname" (the hostname I set). Is this normal?

Thanks again

Re: Hostname web server problem

Posted: Mon Aug 20, 2012 8:24 pm
by nroff-man

You need to edit the hosts file on the machine you are
connecting *from* since this is where the name is looked
up prior to creating a connexion to the RPI.



Re: Hostname web server problem

Posted: Mon Aug 20, 2012 9:06 pm
by M.M
EDIT: nroff-man was faster but, nevertheless... :D

Hi GuitarTater,

ok, so apparently your Windows machine doesn't know your Pi's name.

There is a "quick-and-dirty" fix for that. If your Pi's IP address does not change very often and you are not interested in setting up a whole nameserver and such, this might be what you need:

Assuming you use Windows 7
- Go to the Start menu and find Notepad (or any file editor you like)
- Right click on it and choose "Run as Administrator"
- Open the file C:\Windows\system32\drivers\etc\hosts
- Insert IP and name of the Pi like shown in the examples within the file
- Save it and you are done :)

If the file does not show, it is possible that your folders are set to making hidden files invisible. You can make them visible again by pressing WINDOWS KEY + E taking you to the Windows Explorer and then hitting the ALT key to access the menu bar. Navigate to "Tools -> Folder Options" and in the paragraph about "Hidden files and folder" select "Show hidden files and folders". Now you should be able to access the file as described above.


Re: Hostname web server problem

Posted: Tue Aug 21, 2012 11:36 am
by GuitarTater
Thanks :) That's now worked