Changing the hostname should update both the running name that applications see now and the static name that survives reboot. Renaming a fresh Linux install from a generic value such as host keeps prompts, logs, monitoring, inventory, and remote administration tied to the intended machine.
On systemd-based systems, hostnamectl talks to systemd-hostnamed and manages the static, transient, and pretty hostname values from one interface. The static hostname is the saved system identity, while a transient hostname can come from network configuration and is ignored once a valid static hostname is set.
Use a DNS-safe short label such as web-01 unless the local standard requires a fully qualified domain name. After the rename, check the local hosts file because Debian and Ubuntu-style hosts may still map the previous short name on a loopback line, and treat a name that changes back later as a sign that cloud-init or configuration management still owns the system identity.
$ hostnamectl status
Static hostname: host
Icon name: computer-vm
Chassis: vm
Operating System: Ubuntu 24.04.3 LTS
Kernel: Linux 6.8.0-90-generic
If hostnamectl is missing or the system bus is unavailable, the host is not using the systemd hostname-management path documented here.
$ sudo hostnamectl hostname web-01
Use a single lowercase DNS label such as web-01 unless the environment standard requires a fully qualified domain name such as web-01.example.net. Older distributions may document the compatible form sudo hostnamectl set-hostname web-01.
Tool: Hostname Naming Standard Checker
If the old hostname appears in DNS records, SSH trust, TLS certificates, monitoring targets, or configuration-management data, update those references separately before treating the rename as complete.
$ hostnamectl status
Static hostname: web-01
Icon name: computer-vm
Chassis: vm
Operating System: Ubuntu 24.04.3 LTS
Kernel: Linux 6.8.0-90-generic
$ hostname web-01
$ cat /etc/hostname web-01
If /etc/hostname does not match the static name from hostnamectl, or the name reverts later, another management layer such as cloud-init or configuration management is rewriting it.
$ cat /etc/hosts 127.0.0.1 localhost 127.0.1.1 host ::1 localhost ip6-localhost ip6-loopback
Some distributions do not use a 127.0.1.1 hostname line. If the old name is not present, skip the /etc/hosts edit.
$ sudo cp /etc/hosts /etc/hosts.bak
$ sudoedit /etc/hosts
127.0.0.1 localhost 127.0.1.1 web-01 ::1 localhost ip6-localhost ip6-loopback
Keep the localhost entries unchanged and replace only the host-specific hostname fields on the 127.0.1.1 line.
Related: How to edit the hosts file in Linux
$ getent hosts web-01 127.0.1.1 web-01
getent hosts follows the system resolver path. Tools such as dig and nslookup query DNS directly and do not prove that /etc/hosts was updated.