How To Change A Hostname In Linux – RHEL / CentOS 7 & 8

In this article, you will learn the step by step process of how to change a hostname in Linux (Red Hat /CentOS 7, 8 and 9) by editing “/etc/hostname” file, and by using the hostnamectl tool.

Steb By Step Process Of How To Change A Hostname In Linux (RHEL /CentOS 7/8/9)

Take the following steps to rename a hostname

1. open the “/etc/hostname file”

[root@HQDEV1 ~]# vi /etc/hostname

2. Edit the file to your desired hostname. In my case, I want to change the hostname to “tekneed”


3. restart the systemd.hostnamed service

[root@HQDEV1 ~]# systemctl restart systemd-hostnamed.service

4. Verify

[root@HQDEV1 ~]# hostname

NB: If you are logged in via SSH, you may need to open another SSH session to see the hostname reflected

change a hostname in Linux

We can also use a second method, as shown below to change the hostname in RHEL 7, RHEL 8, and RHEL 9 systems.

Step By Step Guide Of How To Change a Hostname In Red Hat Enterprise Linux 9 (RHEL 9)

We can use the hostnamectl tool to change the hostname as seen below

[root@Tekneed ~]# hostnamectl set-hostname tekneed


[root@HQDEV1 ~]# hostname


Your feedback is welcomed. If you love others, you will share with others

Be the first to comment

Leave a Reply

Your email address will not be published.