table of contents
| HOSTNAMECTL(1) | hostnamectl | HOSTNAMECTL(1) |
NAME¶
hostnamectl - Control the system hostname
SYNOPSIS¶
hostnamectl [OPTIONS...] {COMMAND}
DESCRIPTION¶
hostnamectl may be used to query and change the system hostname and related settings.
systemd-hostnamed.service(8) and this tool distinguish 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 the user-configured hostname (e.g. "lennarts-laptop"), and the transient hostname which is a fallback value received from network configuration (e.g. "node12345678"). If a static hostname is set to a valid value, 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).
Use systemd-firstboot(1) to initialize the system hostname for mounted (but not booted) system images.
COMMANDS¶
The following commands are understood:
status
Added in version 195.
hostname [NAME]
The static and transient hostnames must each be either a single DNS label (a string composed of 7-bit ASCII lower-case characters and no spaces or dots, limited to the format allowed for DNS domain name labels), or a sequence of such labels separated by single dots that forms a valid DNS FQDN. The hostname must be at most 64 characters, which is a Linux limitation (DNS allows longer names).
If the question mark character "?" appears in the hostname, it is automatically substituted by a hexadecimal character derived from the machine-id(5) when applied, securely and deterministically by cryptographic hashing. Example: "foobar-????-????" will automatically expand to "foobar-92a9-061c" or similar, depending on the local machine ID.
Added in version 249.
icon-name [NAME]
Added in version 249.
chassis [TYPE]
Added in version 249.
deployment [ENVIRONMENT]
Added in version 249.
location [LOCATION]
Added in version 249.
tags [TAG...]
Alternatively, each argument may be prefixed with "+" or "-" to incrementally update the configured tags rather than replacing them: an argument prefixed with "+" adds all of its (colon-separated) tags to the list, one prefixed with "-" specifies a removal pattern. For example, hostnamectl tags +foo:bar -quux:ooo=* adds the tags "foo" and "bar" and removes "quux" and any assignment of "ooo=". The prefix applies to the whole argument, i.e. to every tag listed within it. Adding a "key=value" tag replaces any value previously assigned to the same key. Prefixed and unprefixed arguments may not be combined in a single invocation. Removal patterns may use shell-style globbing to remove any matching tags, glob(7).
If --apply is specified, no TAG arguments may be given. Instead, systemd-hostnamed is asked to apply the tag configuration declared in the machine-tags.d/ directories, see machine-tags.d(5).
Machine tags are short labels that may be used to classify and group machines for management purposes, for example to identify the role a machine plays in a deployment, the fleet or organizational unit it belongs to, or any other administrator-defined attribute. Each individual tag must be 1...255 characters long and consist only of ASCII alphanumeric characters, "-", "." and "=". A tag may optionally be parameterized with a value, in the form "key=value", in which case the same key may not be assigned more than one distinct value. The tags are stored in the TAGS= field of /etc/machine-info; see machine-info(5) for details. They may also be matched against with the ConditionMachineTag=/AssertMachineTag= unit settings, see systemd.unit(5).
Added in version 261.
OPTIONS¶
The following options are understood:
--static, --transient, --pretty
This selection does not apply to JSON output: with --json=, status always prints the full status object.
If used with hostname, only the selected hostnames will be updated. When more than one of these switches are specified, all the specified hostnames will be updated.
Added in version 195.
--apply
When this option is used, tags to apply cannot be listed on the command line.
Added in version 263.
-H, --host=
-M, --machine=
--no-ask-password
-h, --help
--version
--json=MODE
-j
EXIT STATUS¶
On success, 0 is returned, a non-zero failure code otherwise.
SEE ALSO¶
systemd(1), hostname(1), hostname(5), machine-info(5), machine-tags.d(5), systemctl(1), systemd-hostnamed.service(8), systemd-firstboot(1)
NOTES¶
- 1.
- Icon Naming Specification
| systemd 263~rc1 |