Hostname is the unique name assigned to the computer to identify over the network easily. To view the computer name in Redhat and CentOS 6/7 use the command hostname.
In order to change the hostname in Linux, you should logged in as root user and follow the below steps.
On CentOS/Redhat 6
Go to the line HOSTNAME and replace the new hostname you want to use.
After changing the name save and exit the vi editor. Open the file hosts located in the path /etc/hosts and replace the hostname.
Once you have changed the hostname in both the files(network and hosts) restart the network using the below command.
#service network restart
On CentOS/Redhat 7
In the Centos/Redhat 7 there are two ways to change the hostname. You can change the hostname by editing the file located in the dir /etc/hostname or by running the command nmtui.
Replace the existing hostname with the desired name you want to use and save and exit the vi editor. In order to apply the changed made run the below command to restart the server to apply the changes.
# init 6