Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Change the Hostname on Ubuntu

Give your Ubuntu server a new name with hostnamectl and keep it after a reboot.

VPS and Cloud Servers1 min read5 steps

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

  1. Check the current hostname:
hostname
  1. Set the new one. Replace new-hostname with your name:
sudo hostnamectl set-hostname new-hostname
  1. 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.

  1. Reboot so every service picks up the change:
sudo reboot
  1. After the reboot, run hostname again 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-hostname changes the name.
  • Update /etc/hosts as well.
  • Reboot, then check with hostname.