Changing the Raspberry Pi’s Hostname

In this Raspberry Pi guide, we will be showing you how to change your hostname.

Changing the Raspberry Pi Hostname

A hostname is a human-readable label that your Raspberry Pi will give out when another network device queries it.

The hostname is a way of labeling different devices without you having to remember the IP address or mac address of each device.

With this guide, we will be showing you how to retrieve your current hostname as well as how to change it.

Knowing how to change the hostname for your Raspberry Pi is essential, especially when you have multiple Pi’s connected to the same network.

Having different hostnames will help you differentiate between each Raspberry Pi.

In this guide, you can see several different methods for changing the hostname. You can change the hostname using the terminal, the raspi-config tool, and the desktop interface.

Equipment List

Here is a list of the equipment we recommend for this guide on changing your Raspberry Pi’s hostname.

Recommended

Optional

Checking the hostname of your Raspberry Pi

Our first task is to check what the current hostname of our device is. Luckily for us, this is a very straightforward task and requires us to run a single command.

1. All you need to do is run the following command in the terminal of your Raspberrry Pi to retrieve it’s hostname.

hostname

2. From this command, you should end up seeing a result showing the hostname of your device.

raspberrypi

Changing the hostname of your Raspberry Pi using the terminal

In this section, we will be walking you through the straightforward steps of changing the hostname of your device within the terminal.

To be able to change the hostname of your device, you will need to be using a user that has superuser access.

1. Luckily for us, modifying the hostname for your Raspberry Pi is a relatively easy task.

To start, we need to modify a file called hostname that resides in the /etc/ folder.

Begin modifying this file by running the following command within the terminal of your Pi.

sudo nano /etc/hostname

2. To change your hostname, all you need to do is swap out the one in this file.

For example, let’s say that we wanted to change our hostname to pimylifeup.

To do this, we would change the file, so it looks like the following.

pimylifeup

3. Once you are happy with the hostname, please save the file by pressing CTRL + X, then Y, followed by ENTER.

4. Next, we need to modify the /etc/hosts file as the hostname is referenced within there too.

Modify the file by using the command below.

sudo nano /etc/hosts

5. Within this file, find the following line and replace the hostname with your own.

For our example, we will be using the hostname pimylifeup.

Find

127.0.1.1       raspberrypi

Replace With

127.0.1.1       pimylifeup

6. Once you have finished making the necessary changes, please save the file by pressing CTRL + X, then Y, followed by ENTER.

7. For other devices to start seeing the new hostname of our Raspberry Pi, we will need to go ahead and restart it.

We can restart the Pi by using the following command.

sudo reboot

Using raspi-config to change the hostname

In this section, we will be showing you how to use the raspi-config tool to change the hostname on your Raspberry Pi.

Using this tool is slightly faster and easier than using the terminal.

1. To start, we will need to load the raspi-config tool by using the command below.

sudo raspi-config

2. The option to change the hostname is located within the “Network Options” page.

Select this option by using the arrow keys and ENTER.

Raspberry Config Network Options

3. Now select “N1 Hostname” and press ENTER.

Change hostname raspi-config tool

4. The next message will explain the characters that you can use for a hostname.

Once you have read through this message, press ENTER to proceed.

Hostname naming warning

5. Finally, you can enter the hostname that you want to give to your Raspberry Pi.

For this example, we are just using the hostname “pimylifeup“.

Setting hostname through Raspberry Pi Configuration tool

Once you are happy with the hostname, press ENTER to change it.

5. When you quit out of the raspi-config tool, you will be asked if you want to reboot now.

Select “<Yes>” and press ENTER to restart now.

Raspi config restart now to change hostname

If you don’t restart your Raspberry Pi, other devices will still use the old hostname.

Changing the Raspberry Pi’s hostname using the desktop

If you are using the desktop interface on your Raspberry Pi, changing your hostname is incredibly straightforward.

The reason for this is that the Raspbian operating system provides a simple interface.

1. To open the Raspberry Pi Configuration tool on the desktop, you need to click the icon in the top left-hand corner.

Click Raspberry Pi Icon

2. With the menu open, hover over “Preferences“, then clickRaspberry Pi Configuration“.

Open Raspberry Pi Configuration Tool

3. Under the “System” tab, you can change the hostname using the textbox (1.).

Once you have set the hostname, click the “OK” button.

Change Pi Hostname in Deskop Config

4. Upon exiting the dialog, you will be asked if you want to restart.

Click the Yes button to finalize your change.

Raspbian Desktop Changed Hostname Please Restart

At this point in the guide, you should now have an idea on how to change the hostname of your Raspberry Pi running the Raspbian operating system.

If you have run into any issues with changing your hostname, feel free to drop a comment below.

2 Comments

  1. Avatar for akash
    akash on

    Dear sir /maa’m

    I have configured using above method but facing one issue when connected on LAN i can access pi with hostname(i.e. ssh username@hostname) but when i connect using wifi i can not access pi with hostname. all device are in same network.

    1. Avatar for Emmet
      Emmet on
      Editor

      Hi Akash,

      My bet would be this has to do with the way your router is handling Wi-Fi traffic vs LAN traffic.

      I don’t believe this is related to the Raspberry Pi itself, however, someone else might correct me on this. The Pi should advertise its hostname on every connected network.

      Cheers,
      Emmet

Leave a Reply

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