Linux

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:
    
     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
    
   
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.
    
     hostname yourserver.mydomain.com
hostname
yourserver.mydomain.com
    
   
Also you need to restart networking on your server to check that changes will persist on restart.
    
     /etc/init.d/network restart
    
   
XsoftHost Support

Share

Recent Posts

Add Extra IP addresses to server configuration On Ubuntu 17.10 and later

Each failover IP address will need its own line in the configuration file. The configuration…

3 years ago

Create RAID Arrays with mdadm on Ubuntu

What is mdadm? The mdadm utility can be used to create and manage storage arrays…

4 years ago

How to change the maximum upload file size for PHP

There are several scenarios that you might need to increase or decrease your php maximum…

6 years ago

How to install Let’s Encrypt Plugin in WHM/cPanel

What is Let’s Encrypt? Let’s Encrypt is a free certificate authority provided by the Internet…

6 years ago

How to install python in my cPanel and add py extension

Python normally installed on all cPanel hosting server because most of Centos/red hat update system…

6 years ago

How to install and enable GUI GNOME Desktop on centos 7

Usually CentOS 7 comes in a numbers of variants, For most users, there are two…

6 years ago