hostnamectl — Manage the hostname and host metadata
Linux / Service and process management / hostnamectl.html
Queries and sets the static and transient hostname plus host metadata.
Basic Information
| Command Name | hostnamectl |
|---|---|
| One-line Introduction | Queries and sets the static and transient hostname plus host metadata. |
| Provided by | systemd |
| Official Documentation | https://www.freedesktop.org/software/systemd/man/hostnamectl.html |
| Supported Operating Systems | Linux (systemd-based distributions) |
| Installation Status | Installed by default with systemd |
| Category | Linux service and process management (tags: Process and resource management (tags: hostname, systemd, system info)) |
What is this command?
hostnamectl reads and changes the hostname managed by systemd.
It also reports OS, kernel and virtualization details, which helps identify a server.
What problems does it solve?
- Rename a server to match its role.
- Check kernel and OS versions quickly.
- Confirm whether the host is virtualized.
- Manage static and transient names separately.
Key features
Status query
Without arguments it prints the name and system information.
- When to use: When reviewing host facts at once
- What you get: Hostname, OS, kernel and virtualization
- Limitations: Some fields depend on privileges
Renaming
set-hostname changes the static hostname.
- When to use: When renaming a host for its role
- What you get: A name that persists across reboots
- Limitations: DNS and /etc/hosts should be consistent
Icon and location
icon-name and location set machine metadata.
- When to use: When distinguishing hosts in a dashboard
- What you get: Display metadata
- Limitations: No functional impact
Installation and usage
Check whether it is installed
hostnamectl --version
systemctl --version # systemd must be PID 1
Real-world examples
Current status
Show host information.
# Show hostname and system details
hostnamectl
Rename
Set the static hostname.
# Set the static hostname
sudo hostnamectl set-hostname web-01
Location
Store the rack location as metadata.
# Record a location string
sudo hostnamectl set-location 'rack A12'