How to configure server hostname in Red Hat Linux Enterprise Server

In RHEL (Red Hat Enterprise Linux) the administrator has several methods to define the server name. By default, the Linux has a static host name which is defined in the /etc/hostname file, there is also the transient hostname which is a name that is dynamic and it is maintained by the kernel, and it can be changed during execution by network services, such as DHCP.


The first step is to identify the current server name, and we can do that by running the following command on the terminal.


Method 01 – Using hostname

The most orthodox method is editing the file hostname located on the /etc


We can use any text editor (I’m using vi), and on the first line we can identify the server name.


Method 02 – Using the Network Manager Text User Interface (TUI)

It is similar to the old format to install Red Hat, in the terminal type in nmtui and on the new menu, select Set System hostname


Type in the hostname of the server and click on OK and confirm all subsequent window.



Method 03 – Using hostnamectl

Another method is using the hostnamectl and we can use the following command to retrieve the information about the static, transient and icon name of the computer.

hostnamectl status

In order to change the hostname we can use 
hostnamectl set-hostname

Method 04 – Using Network Manager CLI (Command Line Interface)

Another possible method is using the command line interface of network manager to change the static hostname.  To check the current server name you can use:
nmcli general hostname
To change the hostname, use the following command
nmcli general hostname

Refreshing the settings…

When changing the static hostname, in some cases it is required to refresh the settings, and we can do that by running the following command. 
systemctl restart systemd-hostnamed