What is a hostname?
The hostname is the name of your computer on a network. It shows in the terminal prompt, in logs and in how other machines see yours. People change it after a rebrand, to follow a naming rule, or to make a server easier to recognise.
Before you change it
- Back up important files and config.
- Check that the new name does not clash with another machine on the network.
- Find the services that use the old name and plan to update them.
- Watch the system logs after the change.
Steps
- Check the current hostname:
hostname
- Set the new one. Replace
new-hostnamewith your name:
sudo hostnamectl set-hostname new-hostname
- Open the hosts file:
sudo nano /etc/hosts
Find the line with the old name and change it to the new name. Save the file.
- Reboot so every service picks up the change:
sudo reboot
- After the reboot, run
hostnameagain to confirm.
Tip: Use only letters, numbers and hyphens. Keep the name short and do not start or end it with a hyphen.
Quick recap
hostnamectl set-hostnamechanges the name.- Update
/etc/hostsas well. - Reboot, then check with
hostname.