Recently, I’ve noticed that the hostnames of many IDC providers’ servers are localhost.localdomain. As someone with a bit of OCD, I find this name too long and unpleasant to look at, so I searched for some information on how to change the hostname. I summarized it and wrote a feasible tutorial, which I’ll share with you below.

Since the hostname-changing mechanism was altered in the CentOS 7.x series, this tutorial is only applicable to the 6.x series. As for whether it can be used on 5.x, please test it yourself.

Tutorial

  1. Connect to SSH using SFTP and download the network file under the /etc/sysconfig/ path.
  2. Open the file with a professional editor (not Notepad). It contains a line:
HOSTNAME=localhost.localdomain

Change localhost.localdomain to the hostname you want to set.

  1. Download the hosts file under the /etc/ path.
  2. Change all instances of localhost.localdomain to the hostname you want to set.
  3. After restarting, use the uname -n command to view the current hostname.