How to change the hostname in CentOS 6

by Daniel Pham
Published: Updated:

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]


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
Edit hostname in file /etc/sysconfig/network

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

Read moreChange 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
Add ip and hostname to file /etc/hosts.

Then, you reboot the server.

(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).

0 0 votes
Article Rating

You may also like

Notify of
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.



Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 – All rights reserved.

Please write sources “” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Would love your thoughts, please comment.x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.