Rename a CentOS 7 host

Simple and official way to rename a host:

hostnamectl set-hostname centos7-base.cantabrian

Then restart the host.

You should find the new name is reflected in the file:

/etc/hostname

Note: You only need to edit “/etc/resolv.conf ” if you are changing workgroups or domains.

Get hostname details

You can use hostnamectl to get other details by running:

hostnamectl status

Which gives:

Static hostname: centos7-base.cantabrian
Icon name: computer-vm
Chassis: vm
Machine ID: 71c11ed5c0aa41ad909ab96d4c6ad395
Boot ID: a7f1d108ceae42e796e43ea0cd249e6b
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-957.27.2.el7.x86_64
Architecture: x86-64

 

Additional stuff

These are things that I need to do when I rename my centos7-base VM. They may or may not apply to you.

AWStats

Update the “HostAliases” section in the config file:

/etc/awstats/awstats.www.zoyinc.com.conf