VMware ESXi and vSphere Cluster Management
How to Change a Raspberry Pi Hostname
Learn how to rename a Raspberry Pi with raspi-config or terminal commands, update local hostname files, reboot, and verify the new network identity.
A hostname is the human-readable name that the operating system and network services use to identify a computer. Raspberry Pi OS commonly starts with a default hostname such as raspberrypi.
The hostname can appear in terminal prompts, router client lists, network-discovery tools, and local name resolution. When multicast DNS (mDNS) is available, you may be able to reach a Raspberry Pi with a name such as raspberrypi.local.
Giving each Raspberry Pi a unique hostname makes a home network easier to manage. For example, pi-office and pi-workshop are easier to distinguish than two devices both named raspberrypi. A descriptive name such as home-automation-pi also communicates the device's purpose.
Hostname naming guidelines
Choose the name before changing the configuration. Use a short, memorable name that is unique on your local network.
- Use letters, digits, and hyphens.
- Avoid spaces, underscores, punctuation, and other special characters.
- Prefer lowercase names for broad compatibility.
- Begin and end with a letter or number rather than a hyphen.
- Do not reuse the same hostname on multiple devices on the same local network.
| Guideline | Valid example | Invalid or discouraged example | Reason |
|---|---|---|---|
| Allowed characters | pi-office | pi.office! | Letters, numbers, and hyphens are broadly supported. |
| No spaces | pi-workshop | pi workshop | Spaces can break commands and local name resolution. |
| Hyphen placement | sensor-pi | -sensor-pi- | A name should begin and end with a letter or number. |
| Use of lowercase | kitchen-pi | KitchenPi | Lowercase avoids case-related differences between tools. |
| Unique names per network | pi-office and pi-workshop | Two devices named raspberrypi | Unique names prevent confusion and local naming conflicts. |
Ways to change a Raspberry Pi hostname
| Method | Best for | Main steps | Files edited | Reboot required |
|---|---|---|---|---|
raspi-config interactive utility | Most users, especially beginners | Open the utility, choose the hostname setting, enter a name, and confirm. | The utility updates the relevant system files. | Yes |
Manual terminal editing with nano | Users who need direct control or are working without the menu utility | Edit the persistent hostname and the applicable local hosts mapping. | /etc/hostname and /etc/hosts | Yes |
Method 1: Change the hostname with raspi-config
raspi-config is a Raspberry Pi OS configuration utility for changing system settings. Open a terminal and run it with sudo. sudo runs a command with administrative privileges.
sudo raspi-config
- Use the arrow keys to select Advanced Options, or the equivalent menu section in your Raspberry Pi OS version.
- Select the option for changing the Hostname. Menu names and numbering can vary between Raspberry Pi OS releases.
- Read the notice explaining what the hostname is used for, then confirm that you want to continue.
- Enter the replacement name, such as
pi-office, and accept the change. - Exit the utility. When prompted, choose to reboot, or reboot manually with
sudo reboot.
A reboot is required before the new name is fully active across the operating system and network services.
Method 2: Change the hostname by editing system files
This method changes the configuration directly. The persistent hostname is stored in /etc/hostname. The file normally contains one hostname value on its own line.
Edit /etc/hostname
- Open the file in the terminal editor
nano:
sudo nano /etc/hostname
- Replace the existing value with the new hostname, for example
pi-office. - Save the file and exit nano using the shortcuts described below.
Edit /etc/hosts
/etc/hosts is a local name-resolution file. It maps names to IP addresses on the Raspberry Pi itself. Open it with:
sudo nano /etc/hosts
Find the local mapping that contains the former hostname. A common pattern is similar to this:
127.0.0.1 localhost
127.0.1.1 raspberrypi
Replace only the old hostname token in the relevant local loopback entry, while retaining its IP-address portion. For example:
127.0.0.1 localhost
127.0.1.1 pi-office
Do not make unrelated changes to the localhost entry or other host mappings. The value in this applicable local mapping should match the value in /etc/hostname.
Saving changes in nano
nano is a terminal-based text editor. Its shortcut instructions appear at the bottom of the screen. The caret symbol means the Ctrl key; for example, ^O means Ctrl+O.
- Press
Ctrl+Oto write, or save, the file. - Press
Enterto confirm the filename shown by nano. - Press
Ctrl+Xto exit nano.
Reboot and verify the new hostname
After using either method, restart the Raspberry Pi so the new identity is applied cleanly:
sudo reboot
The reboot interrupts running programs and ends active remote sessions. Wait for the Raspberry Pi to start completely, then open a local terminal or reconnect remotely and run:
hostname
The command should print the new short hostname, such as pi-office. On systemd-based installations, you can inspect additional hostname information with:
hostnamectl
You can also try hostname -f to inspect the fully qualified local identity when that information is configured and available.
Finally, check the router's connected-device list, a network browser, or your SSH connection target. With mDNS available, a device named pi-office may be reachable as:
ssh user@pi-office.local
Remote-access considerations
If you changed the hostname over SSH, the SSH session may disconnect during the reboot. The old network name should no longer be relied upon after the rename.
- Reconnect with the new name, such as
pi-office.local, when mDNS and local name resolution are available. - Otherwise connect using the Raspberry Pi's current IP address.
- Check the router's client list if you do not know the current address.
- Use a local display and keyboard if the device cannot be found through the network.
A hostname change does not necessarily give the Raspberry Pi a new IP address. However, reconnecting to Wi-Fi or a DHCP lease change can result in a different address, so verify the address if the new hostname is not reachable.
Troubleshooting
The hostname did not appear to change
- Run
hostnameafter startup to check the active name. - Review
/etc/hostnameand confirm that it contains the intended value. - Check that the change was saved in nano with
Ctrl+Oand filename confirmation. - Confirm that the correct hostname field was used in
raspi-config. - Reboot the Raspberry Pi and verify again.
The new .local address does not work
The .local form depends on mDNS, a local-network naming mechanism. It may be unavailable on the client device or network.
- Connect using the Raspberry Pi IP address instead.
- Check the router's connected-device list.
- Make sure the Raspberry Pi has finished rebooting.
- Check that the hostname uses only supported characters.
SSH access stopped after the rename
- The previous SSH command may still use the old hostname. Replace it with the new hostname.
- Try the new
.localname if mDNS is available. - Use the current IP address if name resolution fails.
- Find the address through the router, a local terminal, or a network scan.
Editing /etc/hosts caused local name-resolution issues
Restore the correct loopback and localhost entries if an unrelated line was changed. Ensure that only the former device-name reference in the applicable local mapping was replaced with the new hostname. Do not alter unrelated addresses or host mappings.
The chosen name is rejected or behaves inconsistently
Choose a unique lowercase name made from letters, numbers, and internal hyphens. Avoid spaces, underscores, punctuation, unsupported symbols, and leading or trailing hyphens. Also check that another device on the local network is not already using the same name.
Quick checklist
- Choose a short, lowercase, unique hostname.
- Use
sudo raspi-config, or edit/etc/hostnameand the relevant entry in/etc/hosts. - Save nano changes with
Ctrl+O,Enter, then exit withCtrl+X. - Run
sudo reboot. - Verify the result with
hostnameand, when useful,hostnamectlorhostname -f. - Reconnect using the new hostname or the Raspberry Pi's current IP address.
For the complete procedure in one place, see the Raspberry Pi hostname change guide.