centos7 modify hostname

In CentOS, there are three defined hostnames: static, transient, and pretty.
The "static static" hostname, also known as the kernel hostname, is the hostname that the system automatically initializes from /etc/hostname at boot time.
A "transient" hostname is a hostname that is temporarily assigned while the system is running, for example, via a DHCP or mDNS server.
"Pretty" hostnames allow free-form (including special/whitespace characters) hostnames to be displayed to end users. Both
static and transient hostnames follow the same character restrictions as Internet domain names. Flexible is not limited by this

1. To view hostname related settings:
# hostnamectl  



2. To view only static, transient or flexible hostnames, use the "--static", "--transient" or "--pretty" options respectively
[root@localhost ~]# hostnamectl --static
localhost.localdomain
[root@localhost ~]# hostnamectl --transient
localhost.localdomain
[root@localhost ~]# hostnamectl --pretty


3. To modify all three hostnames simultaneously: static, transient and flexible hostnames:
[root@localhost ~]# hostnamectl set-hostname Linuxidc
[root@localhost ~]# hostnamectl --pretty
node-2
[root@localhost ~]# hostnamectl --static
node-2
[root@localhost ~]# hostnamectl --transient
node-2


4. Modify only one of the hostnames
[root@localhost ~]# hostnamectl --static set-hostname node-2



When modifying a static/transient hostname, any special characters or whitespace characters are removed, and any uppercase letters in the supplied arguments are automatically converted to lowercase. Once the static hostname is modified, /etc/hostname will be updated automatically. However, /etc/hosts is not updated to save changes, so you must manually update /etc/hosts every time you change the hostname before restarting CentOS 7. Otherwise the system will be very slow when restarting.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326514324&siteId=291194637