hostnamectl
Control or change the system's hostname
TLDR
Get the hostname of the computer
Set the hostname of the computer
Set a pretty hostname for the computer
Reset hostname to its default value
SYNOPSIS
hostnamectl [OPTIONS] [COMMAND]
PARAMETERS
--status
Display current hostname settings (default if no command is given).
set-hostname NAME
Set the system hostname. This can be either a static, transient, or pretty hostname depending on the arguments provided. Use the `set-static`, `set-transient` and `set-pretty` commands for more fine-grained control.
set-icon-name ICON
Set the system icon name, as used by graphical front-ends.
set-chassis TYPE
Set the system chassis type. Valid types are 'desktop', 'laptop', 'server', 'tablet', 'handheld', 'watch', 'embedded', 'convertible', 'detachable'.
set-deployment ENVIRONMENT
Set the system deployment environment. Valid environments are 'development', 'production'.
set-location LOCATION
Set the system location string.
--static
Apply the hostname change to the static hostname. Implies `--no-ask-password`.
--transient
Apply the hostname change to the transient hostname. Implies `--no-ask-password`.
--pretty
Sets only the pretty hostname.
--no-ask-password
Do not prompt for password. (Useful in scripts).
-h, --help
Show help message and exit.
--version
Show package version and exit.
DESCRIPTION
The hostnamectl command is a systemd utility used to query and change the system hostname, related network configuration, and operating system metadata. It provides a user-friendly interface to control the system's hostname, which is used to identify the machine on a network. It can set the hostname persistently (across reboots), transiently (until next reboot), or even set a pretty hostname (a more human-readable name). hostnamectl interacts with the systemd hostname daemon, ensuring proper updates to the system's configuration.
This command is crucial for system administrators to manage server and desktop names, making it easier to identify and administer machines. The command provides the ability to check hostname status, set static/transient/pretty hostnames, and control icons related to the system.
CAVEATS
Setting hostname via hostnamectl might require root privileges. The changes made by hostnamectl are persistent across reboots, but transient hostnames are lost upon reboot.
HOSTNAME TYPES
There are three different types of hostnames that can be set.
Static: The traditional hostname, stored in /etc/hostname.
Transient: A temporary hostname obtained from network configuration, lost on reboot.
Pretty: A free-form UTF8 hostname for presentation purposes.
EXIT CODES
hostnamectl returns 0 on success, and a non-zero value on failure.
HISTORY
hostnamectl was introduced as part of the systemd suite. Its development aimed to provide a more structured and reliable way to manage system hostnames compared to older methods, ensuring proper integration with the system's init system and network configuration. Its usage became widespread with the adoption of systemd as the default init system in many Linux distributions.