CentOS change hostname

In order to change or set a CentOS 7 machine hostname, use the hostnamectl command as shown in the below command excerpt.

#hostnamectl set-hostname your-new-hostname

In addition to hostname command you can also use hostnamectl command to display a Linux machine hostname.

#hostnamectl

In order to apply the new hostname, a system reboot is required, issue one of the below commands in order to reboot a CentOS 7 machine.

#shutdown -r