The hostnamectl tool is provided for administering the three classes of hostnames that can be used on a system controller or license server running RHEL 7.

Scope

RHEL 7
The following tips are applicable for RHEL 7. For more information about configuring host names, refer to the Red Hat documentation: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/networking_guide/ch-configure_host_names.

RHEL 9

For information about changing hostnames on RHEL 9 using the nmcli or nmtui tools, refer to the Red Hat documentation: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/configuring_and_managing_networking/assembly_changing-a-hostname_configuring-and-managing-networking#proc_changing-a-hostname-using-nmcli_assembly_changing-a-hostname

View all hostnames

To view all the current hostnames, enter the command:

hostnamectl status

The status option is implied by default if no option is given.

Set all hostnames

To set all the hostnames on a system, as root, enter the command:

hostnamectl set-hostname name

This command changes the pretty, static, and transient hostnames to the name specified in name. The static and transient hostnames are simplified forms of the pretty hostname. Spaces are replaced with "-" and special characters are removed.

Set a particular hostname

To set a particular hostname, as root, enter the command with the relevant option:

 hostnamectl set-hostname name [option...]

Where option is one or more of: --pretty, --static, and --transient.

If either the --static or --transient options are used with the --pretty option, the static and transient hostnames are simplified forms of the pretty hostname. Spaces are replaced with "-" and special characters are removed. If the --pretty option is not specivied, no simplification takes place.

If the pretty hostname to be set contains spaces or a single quotation mark, use quotation marks around the name entry. For example:

hostnamectl set-hostname "Advantest's SmarTest 8.2 system controller" --pretty 

Check a hostname

To check if the hostname is set correctly as a fully qualified domain name, as root, enter the command:

hostname -f 

An example of a correct response is: server123.mycompany.com

Incorrect response example: localhost.localdomain

Clear a particular hostname

To clear a particular hostname and revert to the default, as root, enter the command with the relevant option:

hostnamectl set-hostname "" [option...]

Where:

"" is a quoted empty string.

option... is one or more of: --pretty, --static, and --transient.