Solved: How to change hostname in Redhat Linux

In this post we will see how to change hostname in Redhat Linux 4, 5, 6 and 7 .

For changing the hostname you should have root access. To switch to root do:-

sudo su -

If you want to change the hostname temporarily do as below:-

hostname <new-hostname>
e.g.
hostname cloudvedas

But above change is not permanent and will change back to old name after reboot.

To make the change permanent you will have to make the entry in couple of files. If you are using RHEL 4,5,6 use the below steps, else directly go down to section for RHEL 7. If you don’t want to modify files manually refer this post to change hostname using nmtui or nmcli tools.

RedHat based system use the file /etc/sysconfig/network to read the saved hostname at system boot.

NETWORKING=yes
HOSTNAME=cloudvedas

Next you have to modify /etc/hosts file. Entry in hosts file should look like.

Green Monday Sale! Never stop learning, courses now as low as $10.99
172.25.31.65 cloudvedas

RHEL 7

If you are having RHEL 7 you just have to execute one command which will take care of everything.

hostnamectl set-hostname --static cloudvedas

The above steps will make the hostname change persistent across reboot.

If you want, try to reboot the server with command “reboot” .

Once the server is up, check the hostname.

root# hostname
cloudvedas
root#

It should now show you the new hostname.

If you are using RHEL AMI from AWS marketplace the steps will be slightly different. For that refer our other post How to change hostname in AWS EC2 instance of RHEL 7 .

Leave a Reply

Your email address will not be published. Required fields are marked *