In CentOS or Rhel, there are three defined host names: A, static, B, transient (transient), and C, flexible (pretty). The "Static" hostname, also known as the kernel hostname, is the host name that the system automatically initializes from/etc/hostname at startup. A "transient" hostname is a host name that is temporarily assigned when the system is running, for example, through DHCP or MDNs server assignment. The static hostname and transient host name comply with the same character restriction rules as the Internet domain name. On the other hand, the "flexible" hostname allows the use of a host name of free form (including special/whitespace characters) to be displayed to the end user (such as Dan's computer).
In Centos/rhel 7, there is a command-line tool called Hostnamectl, which allows you to view or modify the configuration associated with a host name.
To view the host name-related settings:
$ HOSTNAMECTL Status
View only static, transient, or flexible hostname, using "--static", "--transient" or "--pretty" options, respectively.
$ hostnamectl Status [--static|--transient|--pretty]
To modify all three host names at the same time: static, transient, and flexible hostname:
$ sudo hostnamectl set-hostname
As shown above, when modifying a static/transient hostname, any special characters or whitespace characters are removed, and any uppercase letters in the supplied parameters are automatically converted to lowercase. Once the static hostname has been modified,/etc/hostname will be automatically updated. However,/etc/hosts does not update to save the changes, so you need to manually update the/etc/hosts.
If you only want to modify a specific hostname (static, transient or flexible), you can use the "--static", "--transient" or "--pretty" option.
For example, to permanently modify a host name, you can modify the static hostname:
$ sudo hostnamectl--static set-hostname
Note that you do not have to restart the machine to activate the permanent hostname modification. The command above immediately modifies the kernel hostname. Log out and re-login to observe the new static hostname at the command prompt.
CentOS 7 Modify hostname