Raspberry Pi online course

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-camera for a camera project
  • pi-media for a media player or server
  • sensor-hub for 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 practiceValid exampleAvoid
Use letters, numbers, and hyphenssensor-hubUnsupported punctuation such as sensor_hub!
Use a lowercase descriptive namepi-cameraUnclear names such as device1
Do not use spacespi-mediapi media
Do not begin or end with a hyphenhome-pi-home-pi or home-pi-
Make the name unique on the local networkgreenhouse-piReusing raspberrypi on every board

Choose a hostname change method

MethodBest forMain actionsRestart required
raspi-configMost users who want a guided workflowOpen the utility, select Advanced Options > Hostname, enter the new name, and finish the promptsYes
Manual terminal editingUsers who prefer the terminal or need to understand the configuration filesEdit /etc/hostname and /etc/hosts with nanoYes

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.

  1. Open a terminal on the Raspberry Pi.
  2. Launch the configuration utility:
sudo raspi-config
  1. Use the arrow keys and Enter to open Advanced Options.
  2. Select Hostname.
  3. Read and acknowledge the displayed notice.
  4. Enter the new hostname, such as pi-camera or sensor-hub.
  5. Complete the remaining prompts and exit the utility.
  6. 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:

  1. Press Ctrl+O to write the file.
  2. Press Enter to confirm the filename.
  3. Press Ctrl+X to 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.

FilePurposeRequired update
/etc/hostnameContains the machine's configured hostnameReplace the existing hostname with the new name on its own line
/etc/hostsContains local hostname-to-address mappingsReplace 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; raspberrypi is a common default.
  • Unique names such as pi-camera, pi-media, and sensor-hub make multiple devices easier to identify.
  • Use lowercase letters, numbers, and hyphens without spaces or leading and trailing hyphens.
  • Use sudo raspi-config and choose Advanced Options > Hostname for the guided method.
  • For manual changes, update both /etc/hostname and /etc/hosts.
  • Reboot, then run hostname to verify the result.

For related skills, see Terminal In Raspbian, Raspi Config, Enable SSH In Raspbian, and Display IP Address.