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.
- The hostnames may have letters (from a to z) and /or digits (from 0 to 9).
- 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.
- It must contain between 2 and 63 characters long.
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.
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
The new values of the content file should be:
127.0.0.1 localhost localhost.localdomain 22.214.171.124 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.