How to change Server Hostname In Centos

We are going to learn here how to change server hostname .

But first what is Server Hostname:

Every server is started with the server’s given name as the hostname. Sometimes when the server host some softwares, such as cPanel, that requires a valid Fully Qualified Domain Name (FQDN) for the hostname to be used during their licensing verification system. So its important to set the FQDN hostname for your server .

Hostname Naming Rules

Hostname can be set to any name you like, but you should keep in mind the following rules:

  • hostnames can contain letters (from a to z) and /or digits (from 0 to 9).
  • Also it can contain only the hyphen character ( – ) as a special character and /or  dot special character ( . ) .
  • hostnames can contain a combination of all above rules but must start and end with a letter or a number , and letters are case-insensitive.
  • hostnames must contain between 2 and 63 characters long.
  • hostnames should be descriptive (to ease identifying the computer purpose, location, geographical area, etc on the network).

How to Change Server Hostname

To modify the hostname, we need to modify /etc/hosts file First you have to Login to your server using root username privileges and edit the file by one of your favorite editor /etc/sysconfig/network by running the following command

					vi /etc/sysconfig/network

then you have to change HOSTNAME= value to your FQDN hostname for example:

Now you need to change the Hostname in the file hosts ,that file used for internal network mapping IPs by running the command
					vi /etc/hosts

The new values of the content file should be

 localhost localhost.localdomain       yourserver
Now you can run the hostname command. This command change the hostname on the server that the command line remembers, but it does not actively update all programs that are running under the old hostname.
Also you need to restart networking on your server to check that changes will persist on restart.
					/etc/init.d/network restart
Share on facebook
Share on twitter
Share on linkedin
Share on telegram
Share on whatsapp

Related Posts