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:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
The
~]$ hostnamectl status
~]$ hostnamectl status
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
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
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 “
root
:
~]# hostnamectl set-hostname name
~]# hostnamectl set-hostname name
-
” 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
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
Where option is one or more of:
root
with the relevant option:
~]# hostnamectl set-hostname name [option...]
~]# hostnamectl set-hostname name [option...]
--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:
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
~]# hostnamectl set-hostname "Stephen's notebook" --pretty
~]# 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
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
Where "" is a quoted empty string and where option is one or more of:
root
with the relevant option:
~]# hostnamectl set-hostname "" [option...]
~]# hostnamectl set-hostname "" [option...]
--pretty
, --static
, and --transient
.
6.3.5. Changing Host Names Remotely
To execute a
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
Where hostname is the remote host you want to configure. The username is optional. The hostnamectl tool will use
hostnamectl
command on a remote system, use the -H, --host
option as follows:
~]# hostnamectl set-hostname -H [username]@hostname
~]# hostnamectl set-hostname -H [username]@hostname
SSH
to connect to the remote system.