STS Host and Tech Knowledge base
Search
Close this search box.

How to change Centos Hostname Server

This article shows us how to change the server hostname.

What is the Server Hostname?

Every server  starts with the server’s given name as the hostname.

It is necessary to  set the FQDN host name for your server because when the server host some softwares, like cPanel, this process requires a valid Fully Qualified Domain Name (FQDN) for the hostname to be used during their licensing verification system.

Hostname Naming Rules

You can give your Hostname the name whatever you want, but you have to consider the following rules.

  1. The hostnames may have letters (from a to z) and /or digits (from 0 to 9).
  2. It can contain only the hyphen character ( – ) as a special character and /or dot special character ( . ) .
  3. 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.
  4. It must contain between 2 and 63 characters long.
  5. The hostnames should be descriptive (to ease identifying the computer purpose, location, geographical area, etc on the network).

How to Change Server Hostname

First you have to Login to your server using root privileges and edit the file /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:

				
					HOSTNAME=yourserver.mydomain.com
				
			

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:

				
					127.0.0.1 localhost localhost.localdomain
93.184.216.34 yourserver.mydomain.com       yourserver
				
			

Execute the hostname command, where it can 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.

				
					hostname yourserver.mydomain.com
hostname
yourserver.mydomain.com
				
			

now you have to restart the network on your server to check that changes will continue on restart.

				
					/etc/init.d/network restart
				
			

Share Article

Related Articles