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.
View only static, transient, or flexible hostname, using "--static", "--transient" or "--pretty" options, respectively.
$ Hostnamectl Status [--static |--< Span class= "KWD" style= "font-family:arial, Verdana, Sans-serif; font-size:12px; Word-wrap:break-word; " >transientpretty /span>
To modify all three host names at the same time: static, transient, and flexible hostname:
$ sudo hostnamectlset< Span class= "pun" style= "font-family:arial, Verdana, Sans-serif; font-size:12px; Word-wrap:break-word; " >-hostname < host -name
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 <host-name>
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.
Via:http://ask.xmodulo.com/change-hostname-centos-rhel-7.html
Translator: Golinux Proofreading: Caroline
This article by LCTT original translation, Linux China honors launch
CentOS7 Modifying host Names