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
- Connect to SSH using SFTP and download the
networkfile under the/etc/sysconfig/path. - 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.
- Download the
hostsfile under the/etc/path. - Change all instances of
localhost.localdomainto the hostname you want to set. - After restarting, use the
uname -ncommand to view the current hostname.