Changing the hostname on a Linux system keeps machine names aligned with their roles, locations, or inventory records. Clear hostnames make it easier to identify systems in SSH prompts, monitoring dashboards, and log files, especially in multi-server environments.
On modern systemd-based distributions, hostname information is managed by systemd-hostnamed and stored primarily in /etc/hostname. The hostnamectl utility communicates with this service to set the static hostname, and optionally pretty and transient hostnames, so that shells, daemons, and network tools agree on how the system identifies itself.
The procedure assumes a systemd-based Linux distribution and access to a user account with sudo privileges. Changing a hostname can temporarily confuse services that cache names or rely on reverse DNS, so adjustments to DNS records, SSH known-hosts, and configuration management should accompany the change on production systems.
Steps to change hostname in Linux:
- Open a terminal.
- Check the current hostname.
$ hostname host
Shows the short system name used in prompts and log files.
- Display detailed hostname information using hostnamectl.
$ hostnamectl status Static hostname: host Icon name: computer-vm Chassis: vm Machine ID: 61d921dfa11f4d9388844883d0ddf7a3 Boot ID: 779dc876f700439599aaa7148d826c6b Virtualization: parallels Operating System: Ubuntu 24.04.3 LTS Kernel: Linux 6.14.0-37-generic Architecture: arm64 ##### snipped #####Confirms that systemd manages the hostname and shows the current static value.
- Set a new static hostname using hostnamectl.
$ sudo hostnamectl set-hostname host.example.net --static
Changing the hostname on a production system without updating DNS, monitoring, and configuration management can cause failed name lookups and confusing log entries.
Some container runtimes block static hostname changes; use a VM or host system if hostnamectl reports a static hostname error.
- Confirm that the running session reports the new hostname.
$ hostname host.example.net
- Verify that the new hostname is stored in /etc/hostname.
$ cat /etc/hostname host.example.net
An incorrect entry in /etc/hostname can cause inconsistent prompts or service identification after reboot.
- Open a new terminal session to ensure prompts and logins display the updated hostname.
$ hostname host.example.net
Opening a fresh session ensures remote shells, SSH connections, and login banners show the new system name.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
