How to Change Hostname of RedHat Linux Server

Last week we had received some requests to rename or change hostname of RedHat Linux systems. We got these requests because the hostname of these linux servers were not as per the server naming convention standard. Here, I will explain how to rename hostname of any redhat linux server. I changed hostname of RHEL servers that are hosted in my lab to show you step by step method.

Related Articles:

There are three methods that i will explain here to rename or change hostname of any Redhat Linux server. These three methods that we will use in this article are given below.

  1. Edit etc/hostname.
  2. nmcli utility.
  3. hostnamectl utility.

Change Hostname of RedHat Linux Server by editing etc/hostname

Connect to your Redhat Linux server and check the hostname by running below command.

#Check hostname using any command.
hostname

#You can run below command as well to check the hostname.
cat /etc/hostname

Check linux hostname

We can see the hostname of this RedHat Linux server is SQLServerRHEL.localdomain. Now we will change this name to TechyazRHEL. If you want to change hostname with fully qualified name then you can write fully qualified name in below command.

#Connect to RHEL as root.
Sudo su

#Change Hostname using /etc/hostname. Make sure to write your new hostname in double quote.
echo "TechyazRHEL" > /etc/hostname

change hostname by editing etc/hostname

You can see when we check hostname of this linux server using hostname command, it is still showing older name SQLServerRHEL.localdomain whereas when we check using cat /etc/hostname it is showing newly changed hostname.

To reflect new host name, we need to restart service systemd-hostnamed. Once you will restart this service, the output of hostname command will also be same as new hostname as shown in above image.

#Restart service systemd-hostnamed
service systemd-hostnamed restart
 or
systemctl restart systemd-hostnamed 

You can see new hostname after restarting above service in above screenshot. One thing you might notice that command prompt is still showing as older hostname i.e. root@SQLServerRHEL. This will disappear if you close this session and connect to new session. Let’s try this by launching new session, you can see new session is showing new hostname in below image.

new session post renaming hostname

Rename Hostname of RedHat Linux Server using nmcli

The nmcli (NetworkManager Command Line Interface) command-line utility is used for controlling Network Manager and reporting network status. nmcli is used to create, display, edit, delete, activate, and deactivate network connections, as well as control and display network device status. Here, we will use nmcli utility to change the hostname of redhat linux server.

Connect to your RedHat Linux server for which you want to change hostname. Run below commands to change hostname of your linux server.

#Connect to RedHat Linux server using root access.
sudo su

#Check existing hostname of RHEL server
hostname

#Change hostname of Redhat Linux server to techyazRHEL-nmCLI. 
#Change your new hostname in place of techyazRHEL-nmCLI.
nmcli general hostname techyazRHEL-nmCLI

#You can also check the hostname of Redhat linux server using nmcli utility.
nmcli general hostname

CHange hostname using nmcli utility

You can see hostname of RHEL server has been changed to techyazRHEL-nmCLI in above screenshot. Your PuTTY terminal will display new hostname once you open new session.

If new hostname is not showing after running above command then you should restart service systemd-hostnamed to reflect changes as we did in first section. You can see new hostname while launching new session in below screenshot.

new session post renaming hostname using nmcli

Rename Hostname of RedHat Linux Server using hostnamectl

The hostnamectl tool is provided for administering the host names in use on a given system. First we will check the existing hostname of this server by running hostname command. We can also check the hostname using hostnamectl utility.

Connect to your Redhat Linux server using root and check the existing hostname.

#Connect to Linux server using root.
sudo su

#Check existing hostname.
hostname
or 
hostnamectl status

#Change hostname to techyazRHEL.
hostnamectl set-name techyazRHEL

change hostname using hostnamectl

You can check the hostname post renaming it. You can see new hostname in above image. Putty terminal will display new hostname once you open new session as shown in below image.

New session to reflect new hostname

We can set all three kind of hostnames (Static, Pretty and Transient) using hostnamectl utility. Static name is mandatory whereas remaining two is optional. If you will not pass any hostname type in above command, same name will be set for all three hostnames. I haven’t used any hostname option in above command so all hostname options will have same name. Let’s check this in below image.

check hostname using hostnamectl utility

I hope you like this article. Please follow our Facebook page and Twitter handle to get latest updates.

Follow me:

Manvendra Deo Singh

I am working as a Technical Architect in one of the top IT consulting firm. I have expertise on all versions of SQL Server since SQL Server 2000. I have lead multiple SQL Server projects like consolidation, upgrades, migrations, HA & DR. I love to share my knowledge. You can contact me on my social accounts for any consulting work.
Manvendra Deo Singh
Follow me:
Summary
How to Change Hostname of Red Hat Linux Server
Article Name
How to Change Hostname of Red Hat Linux Server
Description
Last week we had received some requests to rename or change hostname of some of the RedHat Linux systems. We got these requests because the hostname of these linux servers were not as per the server naming convention standard. Here, I will explain how to rename or change hostname of any redhat linux server. I changed hostname of RHEL servers that are hosted in my lab.
Author
Publisher Name
www.techyaz.com

You may also like...

Leave a Reply

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