CentOS Linux 5/6 Change Hostname Command

To change the hostname in CentOS 5/6, you can follow these steps:

  1. Open the /etc/sysconfig/network file in a text editor:
 
sudo nano /etc/sysconfig/network
  1. Change the HOSTNAME value to the desired hostname:
 
HOSTNAME=new_hostname
  1. Save the file and close the editor.

  2. Restart the network service to apply the changes:

 
sudo /etc/init.d/network restart
  1. Verify that the hostname has been changed by using the following command:
 
hostname

This should display the new hostname. Note that the changes made to the hostname in this manner will not persist across reboots. To make the changes permanent, you will need to set the hostname in the system’s configuration files during the boot process.

Additionally, some modern distributions of Linux, including CentOS 7 and later, use the hostnamectl command to change the hostname. You can use this command as follows:

 
sudo hostnamectl set-hostname new_hostname

Leave a Comment