- Get the hostname of the computer:hostnamectl- Set the hostname of the computer:sudo hostnamectl set-hostname "[some_hostname]"
This tool distinguishes three different hostnames: the high-level "pretty" hostname which might include all kinds of special characters (e.g. "Lennart's Laptop"), the static hostname which is used to initialize the kernel hostname at boot (e.g. "lennarts-laptop"), and the transient hostname which is a fallback value received from network configuration. If a static hostname is set, and is valid (something other than localhost), then the transient hostname is not used.
Note that the pretty hostname has little restrictions on the characters and length used, while the static and transient hostnames are limited to the usually accepted characters of Internet domain names, and 64 characters at maximum (the latter being a Linux limitation).
The static hostname is stored in /etc/hostname, see hostname(5) for more information. The pretty hostname, chassis type, and icon name are stored in /etc/machine-info, see machine-info(5).
Use systemd-firstboot(1) to initialize the system host name for mounted (but not booted) system images.
The following options are understood:
--static, --transient, --pretty
If used with set-hostname, only the selected hostname(s) will be updated. When more than one of these switches are specified, all the specified hostnames will be updated.
The following commands are understood:
Pass the empty string "" as the hostname to reset the selected hostnames to their default (usually "localhost").
Pass an empty string to reset the icon name to the default value, which is determined from chassis type (see below) and possibly other parameters.
Pass an empty string to reset the chassis type to the default value which is determined from the firmware and possibly other parameters.
Pass an empty string to reset to the default empty value.
On success, 0 is returned, a non-zero failure code otherwise.
systemd(1), hostname(1), hostname(5), machine-info(5), systemctl(1), systemd-hostnamed.service(8), systemd-firstboot(1)