Updated: 28 September 2026 · Applies to: Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9

CentOS 7 is end of life. On Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9 the hostname is set with hostnamectl.

  1. Show the current name: hostnamectl
  2. Set a new one (use a fully qualified name that resolves to the server, for example server1.example.com): hostnamectl set-hostname server1.example.com
  3. Add it to /etc/hosts: 192.0.2.10 server1.example.com server1
  4. Log out and in again to see the new name in your prompt.

The change is permanent; no reboot is needed. Create an A record for the name in DNS, and ask support to set the reverse DNS (PTR) record if you send email from the server.

Note: On a cPanel server, change the hostname in WHM with Networking Setup › Change Hostname instead, so cPanel updates its own configuration. On some cloud images, cloud-init resets the hostname at boot: set preserve_hostname: true in /etc/cloud/cloud.cfg.

Hostname rules

  • Use letters, digits and hyphens only; no underscores or spaces.
  • Use a fully qualified domain name (FQDN) such as server1.example.com on servers, especially mail and cPanel servers.
  • Check the result with hostname (short name) and hostname -f (full name).

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket