Change the Hostname of a Raspberry Pi
Learn how to change a Raspberry Pi hostname with raspi-config or terminal commands, choose valid names, update configuration files, and verify the result.
A hostname is the human-readable name assigned to a computer or networked device. On Raspberry Pi OS, it identifies your Raspberry Pi locally and on the local network. A newly installed system commonly uses raspberrypi as its default hostname.
The hostname can appear in the terminal prompt, a router's client list, network discovery tools, and local name-based connections. Giving each board a unique name makes it easier to know which Raspberry Pi you are accessing.
Why change the default hostname?
If you have only one Raspberry Pi, the default name may be sufficient. With multiple boards, however, several devices named raspberrypi can be difficult to distinguish and may cause ambiguous local network identification.
Use a short, descriptive name based on the device's role. For example:
pi-camerafor a camera projectpi-mediafor a media player or serversensor-hubfor environmental monitoring
For example, naming two boards pi-camera and pi-media makes their purpose clear in a router's device list and when connecting to them over the network.
Hostname naming rules
Choose a simple, unique, descriptive hostname. Prefer lowercase names for consistency across tools and systems.
| Recommended practice | Valid example | Avoid |
|---|---|---|
| Use letters, numbers, and hyphens | sensor-hub | Unsupported punctuation such as sensor_hub! |
| Use a lowercase descriptive name | pi-camera | Unclear names such as device1 |
| Do not use spaces | pi-media | pi media |
| Do not begin or end with a hyphen | home-pi | -home-pi or home-pi- |
| Make the name unique on the local network | greenhouse-pi | Reusing raspberrypi on every board |
Choose a hostname change method
| Method | Best for | Main actions | Restart required |
|---|---|---|---|
raspi-config | Most users who want a guided workflow | Open the utility, select Advanced Options > Hostname, enter the new name, and finish the prompts | Yes |
| Manual terminal editing | Users who prefer the terminal or need to understand the configuration files | Edit /etc/hostname and /etc/hosts with nano | Yes |
Normally, choose one method and complete it rather than mixing incomplete steps from both methods. The guided raspi-config method is easier for most users. Manual editing shows exactly where Raspberry Pi OS stores the hostname and its local mapping.
Method 1: Change the hostname with raspi-config
raspi-config is the Raspberry Pi OS configuration utility. You can run it from a terminal, whether you are using the desktop or connecting through a terminal session.
- Open a terminal on the Raspberry Pi.
- Launch the configuration utility:
sudo raspi-config
- Use the arrow keys and Enter to open Advanced Options.
- Select Hostname.
- Read and acknowledge the displayed notice.
- Enter the new hostname, such as
pi-cameraorsensor-hub. - Complete the remaining prompts and exit the utility.
- Restart the Raspberry Pi:
sudo reboot
The reboot applies the new identity consistently. Any open terminal or remote session will be disconnected during the restart.
Method 2: Change the hostname manually in a terminal
This method edits two system files. The sudo command runs an administrative task with elevated permissions. You will use nano, a terminal text editor.
1. Edit /etc/hostname
Open the system hostname file:
sudo nano /etc/hostname
The file should contain the current hostname, normally as a single line. Replace the old entry with the new hostname. For example, the complete file could contain:
pi-camera
Save and exit nano using these controls:
- Press
Ctrl+Oto write the file. - Press
Enterto confirm the filename. - Press
Ctrl+Xto exit nano.
2. Edit /etc/hosts
The /etc/hosts file contains local hostname-to-address mappings. Open it with administrative permissions:
sudo nano /etc/hosts
Find references to the old hostname and replace them with the same new hostname used in /etc/hostname. Do not change unrelated entries. Save with Ctrl+O, confirm with Enter, and exit with Ctrl+X.
| File | Purpose | Required update |
|---|---|---|
/etc/hostname | Contains the machine's configured hostname | Replace the existing hostname with the new name on its own line |
/etc/hosts | Contains local hostname-to-address mappings | Replace local references to the old hostname with the new name |
3. Reboot the Raspberry Pi
After both files are saved, restart the operating system:
sudo reboot
Reboot means restarting the operating system. It allows hostname-related changes to take effect fully across the current system session and network services.
Verify the new hostname
After the Raspberry Pi starts again, open a terminal and run:
hostname
The command should display the new name, for example:
pi-camera
You can also check the terminal prompt, which may include the hostname. On the local network, open the router's client list or another network discovery view and look for the new name. Network lists may take a short time to refresh.
If you connect to the Raspberry Pi by hostname, use the new name for future connections. Existing SSH commands, saved connections, scripts, or bookmarks that use raspberrypi may need to be changed.
Troubleshooting
The hostname still appears unchanged
The edit may not have been saved, or the Raspberry Pi may not have been rebooted. Confirm that the new name was saved in the selected method, run sudo reboot, and then run hostname.
nano cannot save the file
The file was probably opened without administrative permissions. Exit without accepting unintended changes, then reopen it with the appropriate command:
sudo nano /etc/hostname
Use the equivalent command with /etc/hosts when editing the hosts mapping file.
raspi-config rejects the new name
Check for spaces, punctuation, or a leading or trailing hyphen. Use only letters, numbers, and hyphens. A name such as sensor-hub is suitable.
A local service or connection still uses the old name
Make sure the references in /etc/hostname and /etc/hosts match, then reboot. The connecting device may also have cached the old name. Reconnect using the new hostname and allow network lists time to refresh.
The router still shows an unclear device name
Multiple Raspberry Pi boards may still have similar or default names, or the router may not have refreshed its list. Give every board a unique descriptive hostname and wait for the client list to update.
Summary
- A hostname is the local network name of a Raspberry Pi;
raspberrypiis a common default. - Unique names such as
pi-camera,pi-media, andsensor-hubmake multiple devices easier to identify. - Use lowercase letters, numbers, and hyphens without spaces or leading and trailing hyphens.
- Use
sudo raspi-configand choose Advanced Options > Hostname for the guided method. - For manual changes, update both
/etc/hostnameand/etc/hosts. - Reboot, then run
hostnameto verify the result.
For related skills, see Terminal In Raspbian, Raspi Config, Enable SSH In Raspbian, and Display IP Address.