CentOS

How to Change Hostname on CentOS or Cloudlinux?

In order to change the your CentOS or Cloudlinux hostname permanently, you need to edit two files. The files are

  • /etc/sysconfig/network
  • /etc/hosts

Prior to changing the hostname, it is wise to check the existing hostname.

1. To do this issue the following command after SSH to you server

hostname

For example, my hostname is “host.domain.net”

2. Once completed, edit “/etc/sysconfig/network” file by issuing the following command

nano /etc/sysconfig/network

The example output as below,

NETWORKING="yes"
NETWORKING_IPV6="no"
GATEWAYDEV="eth0"
HOSTNAME=host.domain.net
DOMAINNAME=domain.net

3. Look for “HOSTNAME=host.domain.net”, and change to your desire hostname and save the file. Take note on the “hostname” format. It must be fully qualified domain name (FQDN).

4. Next, edit “/etc/hosts” file by issuing the following command

nano /etc/host

The example output as below,

127.0.0.1 localhost
88.88.88.88 host.domain.net

5. Again, look for “host.domain.net”, and change to your desire hostname as above and save the file.

6. Finally, and then rebooting the system

reboot

 


Fix “Remote Host Identification Has Changed” Error

While trying to connect to remote CentOS server through SSH from local CentOS server, I encounter the following error,

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
" ".
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending key in /root/.ssh/known_hosts:1
RSA host key for yourserver.net has changed and you have requested strict checking.
Host key verification failed.

Prior to this I don’t have this issue. This problem happen because I re-install the OS of the remote server.

To fix the error simply editing “/root/.ssh/known_hosts” in the local server. You just need to remove the reference of the remote server. After saving the file the error should be gone.

Another method to fix is just by deleting “/root/.ssh/known_hosts” file