How to Change Hostname on CentOS 7

On this short tutorial, we will learn how to change hostname on CentOS 7 operating system.
Introduction
As a sysadmin, we are sometimes asked by our user to reset the hostname of a server. It doesn’t matter whether the system we are going to change the hostname for is in the cloud, virtual machine or on premise. On this article, we will discuss how to change the hostname on the CentOS 7 operating system.
The steps to change the hostname are as follows :
1. Checking Current Hostname
On this stage, we will check current hostname This task can be performed by submitting command line hostname atau hostnamectl.
Output :
2. Set New Static Hostname
On this stage, we will set a new static hostname. CentOS 7 only allows Fully Qualified Domain Names (FQDNs), for this purpose will do the following steps :
On this tutorial, we will use dev01.bckinf.com as new hostname. Outpu of this command is shown below.
3. Verify the Hostname
Then we will verify again, the last hostname after changing, by submitting command line hostnamectl.
4. Edit the /etc/hosts File
On this stage, we will update /etc/hosts file to change hostname persistently.
In the text editor, look for the line that begins with 127.0.0.1 (the IP address that refers to the system you are working on). It should read:
127.0.0.1 localhost localhost.localdomain localhost 4 localhost4.localdomain4 old.hostname
In this step we have to change the entry old.hostname
to my.new-hostname.server
– and spell it the same as in Step 2.
to be
After all are set, then we reboot the system, and check again by using command line hostnam or hostnamectl.
Conclusion
On this short article, we have learned how to change hostname on CentOS 7 operating system. I hope this guidance will be helpful.