How to change or configure hostname/Server Name in RHEL 7, CentOS 7, RHEL 8 or CentOS 8 systems.




      Host name is the unique identification name of each server. Host name can be given to the server either in ‘short name’ or ‘FQDN’. The configuration file which holds the host name is “/etc/hostname”.

To see the host name of a server, use the below commands.


[root@server01 ~]# hostname


OR
[root@server01 ~]# cat /etc/hostname


OR
[root@server01 ~]# uname -n


[root@server01 ~]# hostnamectl


The command “hostnamectl” is a useful one to work with pretty much all the host name related configuration. Below the options can be used with “hostnamectl” command.



To set the hostname of a server there are different methods available. Below few of the most common methods described.

  1.       By ‘hostnamectl’ command.
  2.       By manual method.

·         By ‘hostnamectl’ command

     This is the recommended way to change the host name in servers running with OS CentOs7/8 or RHEL7/8. By using this command, we can change the host name online. This does not require the reboot of the server to get the new name effected.
The syntax to change the host name is:

# hostnamectl set-hostname <New name>

An example given below to illustrate the host name change of a server with immediate effect. The above screenshots with command output show the current host name of the server as “server01”.

By issuing the below command we will change it to “newserver01”.

[root@server01 ~]# hostnamectl  set-hostname newserver01


The above screenshot shows that the host name has been changed without a reboot of the system and the file /etc/hostname has been updated with new name. The host name of the system can be set as FQDN as below as well.



·         By manual method.

Another method to change the host name is to edit the configuration file manually. Below procedure shows how to do it.

The command hostname shows the current host name.

[root@server01 ~]# hostname


Now edit the configuration file /etc/hostname and change the host name to “newserver01”.

[root@server01 ~]# vim /etc/hostname


After editing this file, we need to issue the hostname command with new host name to set the new name to get the new name assigned to the system. The above command output still shows the old server name.


The command “hostname” can set the host name of the server which will reflect in the current environment and during the reboot of the server the actual name will be picked up from /etc/hostname file. However, to make the host name change globally a reboot is really required.

Conclusion


On RHEL7/ 8 and CentOS 7/8 use the “hostnamectl” command to deal with host name. This is the recommended method for all CentOS and RHEL 7&8 release servers.

Comments

Popular posts from this blog

AIX Firefox Installation

AIX Commands

How to increase swap size on CentOS 8 / RHEL 8

How to configure NTP in RHEL8 or CentOS 8 by chronyd.

System Administration

How to manage Linux systems through web browser (cockpit for Linux): CentOS 7, CentOS 8, RHEL 7, RHEL 8, Fedora, Ubuntu and Debian systems.

How to find big files in Linux, Unix, AIX

Remote X11 forwarding for AIX in command line.

How to enable VNC server (get GUI remotely) in CentOS 7, RHEL 7, CentOS 8 and RHEL 8 servers.

How to change Time Zone in CentOS 8, RHEL 8 and Ubuntu systems