Updated: 30 September 2026 · Applies to: systemd hostnamectl on AlmaLinux and Rocky Linux 9 and 10, RHEL 9 and 10, Ubuntu 24.04 and 26.04, Debian 13

The host name identifies a server in its prompt, logs and emails. On systems with systemd, one command changes it permanently: hostnamectl. There is no need to edit several files as on CentOS 6 (end of life), and no reboot is required.

1. Show the current name

hostnamectl
hostname -f

2. Set a new name

hostnamectl set-hostname server1.example.com

This writes /etc/hostname and takes effect immediately. For a server that sends email or hosts a control panel, use a fully qualified domain name (FQDN) such as server1.example.com that resolves to the server's IP address in DNS.

3. Update /etc/hosts

Make the name resolve locally too, so programs that look up their own name do not wait for DNS. Add a line with the server's IP address, the FQDN and the short name:

203.0.113.10   server1.example.com   server1

Check with hostname -f, which should now print the full name.

4. Apply the name in your session

The shell prompt shows the new name after you log in again, or after exec bash.

Special cases

  • Cloud servers: cloud-init may set the name back at the next boot. Create /etc/cloud/cloud.cfg.d/99-keep-hostname.cfg with preserve_hostname: true.
  • A "pretty" name with spaces for display only: hostnamectl set-hostname --pretty "Web server 1".
  • cPanel servers: change the host name in WHM under Networking Setup > Change Hostname, so cPanel updates its own configuration as well.
  • Mail servers: the reverse DNS (PTR) record of the server's IP should match the new name; ask your provider to change it.

Official documentation: hostnamectl manual.

Ucartz services for this topic

Was this answer helpful? 0 Users Found This Useful (0 Votes)