Skip to main content

How to Change Your Raspberry Pi's Hostname

How to Change a Raspberry Pi Hostname
(Image credit: Tom's Hardware)

By default, any Raspberry Pi that uses Raspbian, the official OS, has “raspberrypi” as its hostname. So, whether you’re trying to use your Raspberry Pi as a web server or set up a headless Raspberry Pi that you access remotely, your board will always be listed as “raspberrypi” on your network. That’s not very helpful when you have multiple Raspberry Pi devices and can’t tell one from the other.

Fortunately, it’s very easy to rename your Raspberry Pi in Raspbian.There are three main ways to change the Raspberry Pi’s hostname and, which one you choose, really depends on your preference for command line or desktop environment. Note that your Raspberry Pi hostname can have numbers, letters, capital letters and hyphens (as long as the first character isn’t a hyphen) but it can’t have special characters.

Change Raspberry Pi Hostname at Command Prompt 

1.  Launch raspi-config by typing: 

sudo raspi-config

 The Raspberry Pi Configuration tool launches. 

2. Select Network Options.

Change Your Raspberry Pi Hostname: Select Network Options

(Image credit: Tom's Hardware)

3.  Select Hostname and hit Enter or select Ok if you receive a warning telling you not to use special characters in Raspberry Pi’s hostname. 

How to Change Your Raspberry Pi Hostname: Select Hostname from Menu.

(Image credit: Tom's Hardware)

4.  Enter a new hostname and hit Enter. 

How to Change Your Raspberry Pi Hostname: Enter a new Hostname

(Image credit: Tom's Hardware)

 5. Click Finish to exit raspi-config. You can get to the Finish button by hitting Tab. 

Change Raspberry Pi Hostname: Click Finish

(Image credit: Tom's Hardware)

6. Select Yes when asked if you’d like to reboot. If you select No then you’ll need to reboot manually for your change to take effect. 

How to Change Your Raspberry Pi Hostname: reboot

(Image credit: Tom's Hardware)

 When your Raspberry Pi reboots, it should have the new hostname. 

Change Raspberry Pi Hostname in Desktop Mode 

There’s no need to go to a terminal window to rename your device. If you’re on the desktop, changing your Raspberry Pi’s hostname is just as easy. 

1.  Launch Raspberry Pi Configuration from the Preference menu.

How to Change Your Raspberry Pi Hostname: Launch Raspberry Pi Configuration Tool

(Image credit: Tom's Hardware)

2.  Enter a new name in the hostname field and click Ok.

Change Your Raspberry Pi Hostname: Enter a new hostname

(Image credit: Tom's Hardware)

3.  Click Yes when prompted to reboot. 

How to Change Your Raspberry Pi Hostname: Click Yes to reboot.

(Image credit: Tom's Hardware)

Change Raspberry Pi Hostname by Editing Config Files 

 
If you’re the kind of person who prefers to get their hands dirty going into text files and changing settings there, you can edit the relevant hosts files directly. The easiest way to get there is from the command line.

1.  Open the /etc/hosts file for editing. 

sudo nano /etc/hosts

2. Change the old Raspberry Pi hostname to your new one and save. In nano, you save by hitting CTRL+X and then Y for yes. 

How to Change Your Raspberry Pi Hostname: Edit /etc/hosts

(Image credit: Tom's Hardware)

3.  Open /etc/hostname for editing. 

sudo nano /etc/hostname

4.  Change the hostname there and save. 

How to Change Your Raspberry Pi Hostname: Edit /etc/hostname

(Image credit: Tom's Hardware)

5. Reboot your Raspberry Pi for the changes to take effect. At the command prompt, you can type the following to reboot. 

sudo reboot