How to Set or Change Hostname in CentOS 7

Use this information when changing the hostname in centos 7.

Ways to show the hostname

# hostname
# hostname -s
# hostname -f
# cat /etc/hostname
# hostnamectl

How to change the 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 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.

# init 6
# systemctl reboot
# shutdown -r now

A second method to setup a CentOS 7 machine hostname is to manually edit the /etc/hostname file

# nano /etc/hostname