How to Set a New Hostname on Raspberry Pi (3 ways)

You have probably already noticed that after the system installation, all Raspberry Pi on Raspbian have the same name
In this post, I will explain to you what it is and how to change it as you want

How to set a new hostname on Raspberry Pi?
On Raspbian you have three main ways to change the device name and set it as you want
The first way is to use raspi-config in a terminal (or SSH)
Another option is to edit the /etc/hostname file
And finally, you can also use the Raspberry Pi Configuration tool on Raspbian Desktop

That’s it for the short answer, I will now give you all the details to use one of this method
I will start by a quick reminder about the hostname role

If you already know what is a hostname, feel free to use the table of contents below to jump directly to the solution you want to use 🙂

The hostname on Raspberry Pi

What is a hostname?

On a network, any device will use a few identifiers like the IP address or MAC address
They also have a label, mainly to help us to identify which device has which IP (the hostname)

For example, when you do a network scan, it will generally give you the IP and MAC address but also a name (the hostname):

You can set almost what you want as a hostname, but you need to avoid using the same hostname on several devices
Valid host names are between 1 and 63 characters, with only letters (a-z), digits (0-9) and hyphen (-)

Raspberry Pi Course
Sale: 10% off today. Take it to the next level.
I'm here to help you getting started on Raspberry Pi, and learn all the skills you need in the correct order.

What is the default value?

On Raspberry Pi, the default value is “raspberrypi”
You can check that with the following command:

Any fresh new Raspbian installation will get this default hostname, even if you already have other Raspberry Pi on your network
Even if it’s not mandatory, it’s a good practice to change it after the installation (we’ll see in the next part how to do this)

3 ways to set a new hostname on Raspberry Pi

Let’s look at how to change the default hostname to a custom name
I will show you three ways to do this now

Edit the file configuration

Open and edit the /etc/hostname file

This first solution works on almost any Linux distribution
There is a file on most systems with the device hostname inside
On Raspbian, this file is /etc/hostname

Here is how to change it:

  • Open the file with nano:
    sudo nano /etc/hostname
  • A file opens that only contains the default hostname: “raspberrypi”
  • Remove the word and replace it by the one you want, for example:
  • Save the file and exit (CTRL+O, CTRL+X)
  • If you now use the hostname command, the value is still the same
    You need to reboot the Raspberry Pi to apply changes
    sudo reboot
  • Once restarted, the new hostname now appears in the command prompt
    And you can also check with the hostname command

Network update

If you have some issues (or warnings at least) with some network services, you probably need to also edit the /etc/hosts file to update the localhost name:

  • Open the /etc/hosts file the same way
    sudo nano /etc/hosts
  • Edit the last line to update the Raspberry Pi name
  • Save and exit (CTRL+O, CTRL+X)
  • Reboot
    sudo reboot

That’s it for this first method
You can use the same thing on systems like Debian and Ubuntu

Use raspi-config

The next two solutions are only available on Raspbian
It can be easier if you don’t remember the filename to edit
You can also check the last one if you are on Raspbian Desktop

The second solution is to use raspi-config
You probably already know this tool, you can use it to change many things in your Raspberry Pi configuration

Here is how to change the hostname in raspi-config:

  • Start raspi-config with:
    sudo raspi-config
  • On the wizard that shows up, click on “Network options”
    Use the arrows to select the second line and press enter to confirm
  • Then click on “Hostname” (press enter)
  • You’ll get a message about the letters you can use (a-z, 0-9 and -)
  • Confirm (Enter) and type your new hostname
  • After the confirmation, you will be back in the main menu
  • Select the Finish option to save your changes (use Tab and press Enter)
  • Raspi-config will ask you to reboot
    Confirm and wait a few seconds
  • Once the system reboot is complete, you can see the new hostname in the command prompt

    Same thing with the “hostname” command

Note: you may also need to follow the “Network update” from the last part if you have errors like this:
sudo: unable to resolve host <hostname>: No address associated with hostname

Use the configuration tool on Raspbian Desktop

The last option I want to show you is to use the Raspberry Pi Configuration Tool on Raspbian Desktop
This is probably the easiest one if you are on this Raspbian version

Here is how to do this:

  • In the main menu, go to Preferences > Raspberry Pi Configuration
  • In the configuration tool, update the hostname field:
  • Click “OK” to save the changes
  • And as with the other solutions, a reboot is need to apply changes
    Click on “Yes” to reboot immediately

Note: In this case, there is no need to update the /etc/hosts file. The wizard will change it for you


That’s it, you now know 3 ways to change the Raspberry Pi name, whatever the Raspbian version you use

I hope this post was useful for you
If you have any remaining question or a suggestion, feel free to post a comment below

Patrick Fromaget

I'm the lead author and owner of My goal is to help you with your Raspberry Pi problems using detailed guides and tutorials. In real life, I'm a Linux system administrator with a web developer experience.

Leave a Reply

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

Recent Posts

Master your Raspberry Pi - eBook Sale