RHEL7, there are three kinds of defined hostname:
A, static: the "static" hostname, also known as the kernel hostname, is the host name that the system automatically initializes from/etc/hostname at startup
b, transient (transient): the "transient" hostname is a host name that is temporarily assigned while the system is running, managed by the kernel, for example, by a DHCP or MDNs server, such as localhost
C, Flexible (pretty): "Flexible" hostname is the UTF8 format of the free host name, to show to the end user
1. Use Nmtui to modify the host name
# Nmtui
After modifying the static hostname (/etc/hostname file) with the Nmtui interface of NetworkManager, Hostnamectl is not notified. To force Hostnamectl to know that the static hostname has been modified, you need to restart the hostnamed service
# systemctl Restart Systemd-hostnamed
2. Use Hostnamectl to modify the host name
#查看主机名
# hostnamectl Status Static hostname:yb.example.com ...
#设置新的主机名
Set-hostname test.example.com
#查看主机名
# hostnamectl Status Static hostname:test.example.com ...
3. NetworkManager command Line Interface nmcli Modify host name
NMCLI can modify the static host name in the/etc/hostname
#查看主机名
[Email protected] ~]# NMCLI General hostnametest.example.com
#设置新的主机名
[Email protected] ~~]# nmcli General Hostnamemytest
#重启hostnamed服务让hostnamectl知道静态主机名已经被修改
[Email protected] ~]# systemctl restart systemd-hostnamed
RHEL7--Modify host name