Show Table of Contents
6.3. Configuring Host Names Using hostnamectl
The hostnamectl tool is provided for administering the three separate classes of host names in use on a given system.
6.3.1. View All the Host Names
To view all the current host names, enter the following command:
~]$ hostnamectl status
The status option is implied by default if no option is given.
6.3.2. Set All the Host Names
To set all the host names on a system, enter the following command as
root:
~]# hostnamectl set-hostname name
This will alter the pretty, static, and transient host names alike. The static and transient host names will be simplified forms of the pretty host name. Spaces will be replaced with “-” and special characters will be removed.
6.3.3. Set a Particular Host Name
To set a particular host name, enter the following command as
root with the relevant option:
~]# hostnamectl set-hostname name [option...]
Where option is one or more of: --pretty, --static, and --transient.
If the
--static or --transient options are used together with the --pretty option, the static and transient host names will be simplified forms of the pretty host name. Spaces will be replaced with “-” and special characters will be removed. If the --pretty option is not given, no simplification takes place.
When setting a pretty host name, remember to use the appropriate quotation marks if the host name contains spaces or a single quotation mark. For example:
~]# hostnamectl set-hostname "Stephen's notebook" --pretty
6.3.4. Clear a Particular Host Name
To clear a particular host name and allow it to revert to the default, enter the following command as
root with the relevant option:
~]# hostnamectl set-hostname "" [option...]
Where "" is a quoted empty string and where option is one or more of: --pretty, --static, and --transient.
6.3.5. Changing Host Names Remotely
To execute a
hostnamectl command on a remote system, use the -H, --host option as follows:
~]# hostnamectl set-hostname -H [username]@hostname
Where hostname is the remote host you want to configure. The username is optional. The hostnamectl tool will use SSH to connect to the remote system.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.