Change hostname in CentOS

How to Change Hostname - CentOS

This KB helps user to change hostname on CentOS. By default your server will be installed with the server's given name as the hostname. Some Control Panel software such as CPanel, DirecAdmin require a valid Fully Qualified Domain Name or FQDN for the hostname to be used during their Licensing verification system.

Here are the steps user can take to change the hostname
1. Open the /etc/sysconfig/network file with your favorite text editor i.e. vi, nano. Modify the HOSTNAME= value to match your FQDN host name.
# sudo nano /etc/sysconfig/network
Edit the file with the hostname you would like to add. For example here hostname is myserver.domain.com
HOSTNAME=myserver.domain.com
2. Change the host file.
Change the host that is associated to your main IPaddress for your server, file path is /etc/hosts.
file looks like below:
127.0.0.1             localhost localhost.localdomain
192.168.1.27         hostname.domain.com  hostname

3. Run Hostname
The 'hostname' command on the command line and it will let you change the hostname on the server. Keep in mind that it will not actively update all programs that are running under the old hostname.
#hostname hostname.domain.com
#hostname
hostname.domain.com
#

4. Restart networking
Now after making all the necessary changes, user needs to restart networking on the server to make sure that changes are implemented:
# /etc/init.d/network restart
Now you are done.



  • 5 Users Found This Useful
Was this answer helpful?

Related Articles

FFMPEG install on CentOS

How to install FFMPEG and FFMPEG-PHP install on CentOS 5.X To install FFMPEG please follow the...

How to set hostname on Centos 6?

In order to permanently set hostname on Centos 6 VPS you neew to run # nano...

How to change hostname on CentOS permanently

If you are installing LAMP on a new server and ran into the following issue with httpd during the...

CentOS: Start custom script automatically after network startup

Find the ifup-post under /etc/sysconfig/network-scripts. This scipt is called right after any...

How to add a new user to CentOS

Open a terminal window and log in to your server via SSH.Create the user by entering the...