How to change the hostname in CentOS 6

Share this post to your friends !
  • 1
    Share

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 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-02 How to change the hostname in CentOS 6
Add ip and hostname to file /etc/hosts.

Then, you reboot the server.

If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.


Share this post to your friends !
  • 1
    Share
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.