hostnamectl Command in Linux: Set and Query Hostname

When you rename a server or provision a new machine, keeping the hostname consistent across logs, monitoring dashboards, and network records prevents confusion. On systemd-based Linux systems, hostnamectl is the standard tool for reading and setting the hostname from the command line, without editing /etc/hostname by hand.
This guide explains how to use hostnamectl to view and change hostnames and related system metadata.
Syntax
hostnamectl [OPTIONS] COMMANDWhen called without a command, hostnamectl shows the current system status, equivalent to running hostnamectl status.
Check the Current Hostname
Run hostnamectl with no arguments to display the full hostname status:
hostnamectl Static hostname: ubuntu-server
Icon name: computer-vm
Chassis: vm
Machine ID: a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4
Boot ID: f7e8d9c0b1a2f7e8d9c0b1a2f7e8d9c0
Virtualization: kvm
Operating System: Ubuntu 26.04 LTS
Kernel: Linux 6.14.0-14-generic
Architecture: x86-64
Hardware Vendor: QEMU
Hardware Model: Standard PC (Q35 + ICH9, 2009)The output shows the static hostname, chassis type, machine and boot IDs, virtualization platform, OS, and kernel version.
To print only the current system hostname, use the hostname command:
hostnamectl hostnameYou can also select a specific hostname type:
hostnamectl --static
hostnamectl --transient
hostnamectl --prettySet the Static Hostname
The static hostname is the administrator-configured name stored in /etc/hostname. It persists across reboots. To change only this hostname, run:
sudo hostnamectl --static hostname web-server-01The system hostname changes immediately, but an existing shell prompt may continue to show the old name. Open a new terminal session to refresh the prompt.
Verify the static hostname:
hostnamectl --staticweb-server-01Static and transient hostnames can be a single DNS label, such as web-server-01, or a valid fully qualified domain name, such as web-server-01.example.com. They are limited to 64 characters by the Linux kernel.
To set the static, transient, and pretty hostnames together, omit the type option:
sudo hostnamectl hostname web-server-01Current systemd releases document the hostname command shown above. Older releases and many existing guides use the equivalent set-hostname form:
sudo hostnamectl set-hostname web-server-01Check hostnamectl --help if you are working on an older distribution.
Set the Pretty Hostname
The pretty hostname is a free-form, human-readable label that can include spaces and mixed case. It is stored in /etc/machine-info and is used by desktop environments and some management tools, not by the kernel or network:
sudo hostnamectl --pretty hostname "Web Server 01"The static and pretty hostnames are independent. You can set them to different values:
sudo hostnamectl --static hostname web-server-01
sudo hostnamectl --pretty hostname "Web Server 01 (production)"Understand Hostname Types
hostnamectl manages three distinct hostname types:
- Static: The administrator-configured hostname stored in
/etc/hostname. It persists across reboots. - Transient: A runtime fallback that can come from network configuration. It is used when no valid static hostname is set.
- Pretty: A free-form label stored in
/etc/machine-info. Used by desktop shells and some management tools. Not used for networking.
Set only the transient hostname with:
sudo hostnamectl --transient hostname temporary-nodeSet the Chassis Type
The chassis type tells system tools and desktop environments what kind of hardware the machine is. To set it:
sudo hostnamectl chassis serverValid chassis types are: desktop, laptop, convertible, server, tablet, handset, watch, embedded, vm, and container. Use vm for virtual machines and container for container environments.
The chassis type is stored in /etc/machine-info alongside the pretty hostname.
Set Deployment and Location
Two additional fields help identify machines in larger environments:
sudo hostnamectl deployment production
sudo hostnamectl location "rack-3 / datacenter-ams"Both are stored in /etc/machine-info and appear in hostnamectl output. They have no effect on system behavior but are useful for inventory and monitoring tools that read machine metadata.
Manage a Remote Host or Container
The -H option runs hostnamectl against a remote machine over SSH. For example, query a server as the admin user:
hostnamectl -H admin@server.example.com statusUse -M to operate on a local systemd machine or container:
hostnamectl -M web-container statusYour account still needs permission to connect to the target and perform the requested operation.
Hostname and Network Configuration
Changing the hostname does not create or update DNS records. If other systems must reach the machine by its new name, update the relevant DNS records separately.
You may also need to update /etc/hosts when it contains an entry for the old hostname. This avoids local name-resolution errors from tools that expect the system hostname to resolve.
On cloud instances, cloud-init or provider metadata can restore a previous hostname during boot. Check the provider settings and the preserve_hostname option in /etc/cloud/cloud.cfg if your change does not persist.
Troubleshooting
hostnamectl: command not found
The command is available on systemd-based distributions. On systems that use another init system, use the hostname command and edit the platform’s hostname configuration file instead.
Could not set property: Access denied
Changing hostname or machine metadata requires administrative privileges. Run the command with sudo, and confirm that your account is allowed to perform privileged operations.
The old hostname returns after reboot
Cloud-init, DHCP, or another provisioning service may be resetting it. Check the system’s cloud and network configuration rather than repeatedly changing the hostname.
Quick Reference
| Task | Command |
|---|---|
| Show system hostname details | hostnamectl |
| Print the current hostname | hostnamectl hostname |
| Print the static hostname | hostnamectl --static |
| Set only the static hostname | sudo hostnamectl --static hostname web-server-01 |
| Set all hostname types | sudo hostnamectl hostname web-server-01 |
| Set a pretty hostname | sudo hostnamectl --pretty hostname "Web Server 01" |
| Set the transient hostname | sudo hostnamectl --transient hostname temporary-node |
| Set the chassis type | sudo hostnamectl chassis server |
| Set the deployment environment | sudo hostnamectl deployment production |
| Query a remote host | hostnamectl -H user@host status |
Conclusion
hostnamectl manages the persistent hostname and related machine metadata on systemd-based Linux systems without requiring a reboot. For a broader walkthrough that includes non-systemd systems, DNS, and /etc/hosts, see how to change the hostname in Linux
.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page