Change Raspberry Pi Hostname

By default the Raspberry Pi has its hostname set to “raspberrypi”. This appears as part of the command prompt when you open a terminal window. You can change it by editing a few system files. This process only takes a minute.

Open a terminal window from your program list. For example “LXTerminal” under “Accessories”.

Type :

sudo leafpad /etc/hostname

followed by ENTER. Type the hostname you require and using the menu save the file and exit.

Then type :

sudo leafpad /etc/hosts

followed by ENTER. Replace all instances of “raspberrypi” with the new hostname that you entered above.

Then you can either reboot by typing :

sudo reboot

followed by ENTER or simply restart the hostname process by typing :

sudo /etc/init.d/hostname.sh start

followed by ENTER.

The hostname as been changed. You new hostname will now be visible in the command prompt when you open a new terminal window.

Please ensure you choose a hostname that only contains upper and lower case letters, numbers and the “-” character.

Alternative Editor

In the steps above we used Leafpad to edit the two system files. An alternative editor is available called Nano. To try this editor use the two commands below to edit the files :

sudo nano /etc/hostname
sudo nano /etc/hosts

The advantage with using Nano is that it can be run from the command line and does not require a graphical interface. This makes it a better choice if you are accessing your Pi remotely using Putty or similar utility.

This entry was posted in Tutorials & Help. Bookmark the permalink.


2 Responses to Change Raspberry Pi Hostname

  1. Andy says:

    Just a note: a hostname can also have numbers (0-9) in it as well as letters (uppercase and lowercase) and the dash “-” character. So “Host-01″, “host-01″ and “host01″ are all valid for example.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>