Change the hostname in CentOS

To change the hostname in CentOS, you will first need to update the hostname line in the /etc/sysconfig/network file.

HOSTNAME=example.randomlinux.com

Once that is changed, you will want to add the IP address for the hostname to /etc/hosts.

127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.1.5 example.randomlinux.com

Then, you need to restart network for the changes to take affect.

service networking restart
or
/etc/init.d/network restart

Once that is done, you should be able to use the hostname command and it should show the new hostname that you set. On my test box I did have to restart the box for it to take affect, so if you don’t see the changes, you may need to reboot.

[root@example ~]# hostname
example.randomlinux.com

Popular Posts
  • No Popular Post Available