How to rename your Raspberry Pi

The Raspbian SD image gives your Raspberry Pi a default name of ‘raspberry’. This name appears in the command prompt. Many people will leave it at the default but you may wish to change it to something more unique.

It’s quick and easy to change by following the steps below.

Step 1 – Hostname File

The first thing to do is edit the /etc/hostname file. You can do this by entering the following command at the command prompt :

sudo nano /etc/hostname

This will lauch the hostname file in the Nano text editor. Change raspberrypi to the name of your choice. In the example below I changed it to mypi.

Press CTRL-X, then Y and finally Enter to save the changes.

You can type the following command to check the file contains the new name :

cat /etc/hostname

Step 2 – Hosts File

The next file that needs to be changed is the /etc/hosts file. We can use the same technique to edit this file.

sudo nano /etc/hosts

Using the cursor keys locate and update the line that says

127.0.1.1    raspberry

to

127.0.1.1   mypi

Here is a screenshot :

Leave the other lines unchanged. Press CTRL-X, then Y and finally Enter to save the changes.

You can type the following command to check the file contains the new name :

cat /etc/hosts

Step 3 – Reboot and Test

All the changes are made but we must reboot for those changes to take effect. Use the following command to reboot the Pi :

sudo reboot

Once the Pi has rebooted your command prompt should now include the new name. You can also type hostname at the command prompt to get your Pi to report its name.

This entry was posted in Raspbian and tagged , , , . Bookmark the permalink.


One Response to How to rename your Raspberry Pi

  1. Graham says:

    Hi Matt

    May I suggest a few simplifications to this guide, the method I regularly use is the following:-


    sudo su
    echo mypi > /etc/hostname
    /etc/init.d/hostname.sh start
    reboot

    the setting of 127.0.1.1 in /etc/hosts is a bug workaround for gnome from as far back as 2005 – So I leave it well alone – other unix systems do not use this method. I’ve left my host name referring 127.0.1.1 to raspberrypi with no ill effects so far..

    Keep up the good work Matt.

    G.

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>