hostnamectl — Manage the System Hostname on systemd

View and set the hostname on systemd Linux: static, transient and pretty names plus chassis, deployment and machine metadata.

hostnamectl is the systemd tool for viewing and changing your Linux machine's hostname from one place, instead of juggling /etc/hostname and the legacy hostname command. systemd tracks three layers: the static hostname (persistent, stored in /etc/hostname), the transient one (kept by the kernel at runtime) and the pretty name (free-form, with spaces and Unicode allowed). On top of that you can record metadata such as the chassis type, icon, deployment environment and physical location. This guide covers the commands you actually reach for on servers and desktops.

Status & Info

hostnamectl — Show current hostname and system info.

hostnamectl

hostnamectl status — Show detailed hostname status (same as no args).

hostnamectl status

hostnamectl hostname — Show only the current hostname.

hostnamectl hostname

Set Hostname

hostnamectl set-hostname '<name>' — Set the static hostname (persists across reboots).

sudo hostnamectl set-hostname webserver01

hostnamectl set-hostname '<name>' --static — Set only the static hostname.

sudo hostnamectl set-hostname webserver01 --static

hostnamectl set-hostname '<name>' --pretty — Set the pretty hostname (free-form, can include spaces).

sudo hostnamectl set-hostname 'Web Server 01 (Production)' --pretty

hostnamectl set-hostname '<name>' --transient — Set the transient hostname (lost on reboot).

sudo hostnamectl set-hostname temp-hostname --transient

Machine Info

hostnamectl set-icon-name '<name>' — Set the machine icon name.

sudo hostnamectl set-icon-name computer-server

hostnamectl set-chassis '<type>' — Set the chassis type (desktop, laptop, server, vm, container).

sudo hostnamectl set-chassis server

hostnamectl set-deployment '<env>' — Set the deployment environment.

sudo hostnamectl set-deployment production

hostnamectl set-location '<location>' — Set the location description.

sudo hostnamectl set-location 'Frankfurt DC, Rack 42'

Conclusion

hostnamectl replaces hand-editing /etc/hostname with one consistent command and cleanly separates the static, transient and pretty hostnames – for everyday use you mostly need plain hostnamectl to read and set-hostname to change. Write actions require sudo, and the tool exists only on systemd systems (it is absent on other init systems and in some minimal containers). Keep in mind, too, that on production servers a hostname is rarely just cosmetic – it shows up in logs, monitoring, TLS certificates and cluster membership. A change can therefore have knock-on effects; plan it deliberately on running systems and recheck dependent services afterwards.

Further Reading

  • timedatectl – manage system time, time zone and NTP synchronisation under systemd
  • systemctl – control and query systemd services and units
  • uname – print kernel and system information