Changing the Hostname of your Raspberry Pi
This guide will show you how to change the hostname of your Raspberry Pi. This assumes that you are already SSHed into your Raspberry Pi. If you are not, see the following: http://www.cpdforteachers.com/resources/sshing-into-your-raspberry-pi/. The hostname identifies your device on the network. Note that this is an operating system option and will persist with the SD card. This means that if you swap the SD cards in two Raspberry Pis, their hostnames will also swap. Furthermore, if you rewrite the SD card the hostname will revert to its default value.
Caveats: While following this guide will change your hostname, depending on your network , you may not be able to detect this change from other computers. This is a problem especially prevalent on Windows machines. If you have problems detecting the change, try using a different Network Interface Card (eg: use your wired card instead of your wireless card or vice versa).
1) Enter the command following command:
sudo nano /etc/hostname
2) Edit the hostname as desired using the keyboard
3) Press Ctrl-O to save and then press the return key to accept the name and overwrite the existing file.
4) Press Ctrl-X to leave the editor and return to the command line
5) Enter the following command
sudo nano /etc/hosts
7) Again, press Ctrl-O to save and then press the return key to accept the name and overwrite the existing file.
8) Press Ctrl-X to leave the editor and return to the command line
9) Now make the change active by running the following command