How to change the hostname in CentOS 6


SystemMen - This article, I will show you how to change hostname in CentOS 6. Unlike operating systems that use systemd like CentOS 7 or Ubuntu 16, CentOS 6 will not have the hostnamectl command for you to use. So how do we change the hostname in CentOS 6?

Change the hostname temporarily

In CentOS there is a command that allows you to change the hostname temporarily, which is the hostname command. This command will change the hostname of the server immediately without reboot. You only need to logout and login again after changing the hostname. Note, after you logout and login again. It may take a while to connect, do not be scared.

hostname [Your-new-hostname]

Example:

hostname systemmen

But when using the hostname command, the value of the hostname will not be saved when the server reboot (problems can occur such as power failure, hardware failure …).

Change the hostname permanently

To change the hostname permanently, you do the following 3 steps. First, you need to edit the file/etc/sysconfig/network.

nano /etc/sysconfig/network
how-to-change-the-hostname-in-centos-6-03 How to change the hostname in CentOS 6
Edit hostname in file /etc/sysconfig/network

Edit the HOSTNAME line with the new hostname you want. Save the file.

Read more: Change the hostname in Ubuntu 16.

Next, edit the /etc/hosts file and add the line in the image below. With IP is the IP of your server, the new hostname you want. This section is optional, you may not need to do this.

nano /etc/hosts
how-to-change-the-hostname-in-centos-6-02 How to change the hostname in CentOS 6
Add ip and hostname to file /etc/hosts.

Then, you reboot the server.

«« »»