Changing a host name in RHEL7 and CentOS 7 Linux is a little different now that it uses SystemD by default. 

You can set the host name of any system with the hostname command.  This will not be a permanent change, as the system will revert back to the old host name after it reboots.

Using hostnamectl Command

You can use the hostnamectl command to change the pretty, transient and static host names (More on that later).  To change all the host names at one time issue the hostnamectl command with the set-hostname option like so:

hostnamectl set-hostname myhost

Replace myhost with the host name of your choice.

To change only one of the three particular host names, use:

hostnamectl set-hostname myhost --static

You can replace static with any of the optional host names.  Valid options are pretty, static or transient.

If setting the pretty host name it is recommended to wrap it in quotes to avoid shell confusion with special characters, like so:

hostnamectl set-hostname "Savona's Laptop" --pretty

To clear a host name use the same command but replace the name with two quotes like so:

hostnamectl set-hostname ""

You can use status to get current information from hostnamectl like so:

hostnamectl status

Example output:

# hostnamectl status
Static hostname: putor
Pretty hostname: Savona's Laptop
Icon name: computer-laptop
Chassis: laptop
Machine ID: 9a544394179e8347be83cc734
Boot ID: 0d11dac360b213edbef30872321090123
Operating System: Fedora 21 (Twenty One)
CPE OS Name: cpe:/o:fedoraproject:fedora:21
Kernel: Linux 3.19.3-200.fc21.x86_64
Architecture: x86-64

Edit the /etc/hostname File Directly

The hostnamectl command will edit the /etc/hostname file if you set the static host name.  You also have the option of editing /etc/hostname directly with vi or your editor of choice.  The file should contain one line with nothing but your host name.

$ cat /etc/hostname
rhel7test

This will not take effect until you reboot.

Different Host Names:
Pretty -vs- Static -vs- Transient

The hostnamectl command distinguishes three different host names. Here is their names and a brief explanation.

Pretty Host Name

The “pretty” host name is a high-level name which can include special characters (e.g. Savona’s Laptop). This name is human readable and is only used for presentation to the local user.

Static Host Name

The static host name is the conventional name most server admins are used to. It is used to initialize the kernel host name at boot.

Transient Host Name

Transient host names are those obtained by network configuration (e.g. DHCP). If a static host name is set and valid, transient host name is not used.

Conclusion

So we covered setting the system host name with hostnamectl, how to clear the host name. We also discussed the difference between pretty, static and transient host names. I hope this helped, if you have any questions or comments we would love to hear from you in the comments.

If you want to know how to change the host name of an older Red Hat 6 or CentOS 6 system read "How to Change a Machines Hostname in Red Hat 6".