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.
- How to Change IP Address, Subnet Mask & Default Gateway of Linux Server
- Fix Error “User is not in sudoers file.
- Installing SQL Server 2017 on Red Hat Linux Server
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.
- Edit etc/hostname.
- nmcli utility.
- 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
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
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.
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
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.
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
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.
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.
Latest posts by Manvendra Deo Singh (see all)
- Understanding Hybrid Buffer Pool in SQL Server - December 30, 2018
- Fix:VIEW SERVER STATE permission was denied on object ‘server’, database ‘master’ - August 30, 2018
- SQL Server Error 5184: Cannot use file ‘I:\Path\Techyaz.mdf’ for clustered server - August 29, 2018