It is recommended to use the first one, which is simple and violent. The changes to /etc/hosts and /etc/sysconfig/network mentioned on the Internet have no effect.
In CentOS7, there are three defined hostnames: static, transient, and pretty. A "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. Both static and transient hostnames follow the same character restrictions as Internet domain names. "Flexible" hostnames, on the other hand, allow free-form (including special/whitespace characters) hostnames to be displayed to end users.
method one
Use hostnamectl to modify the hostname.
- [root@Geeklp201 ~]# hostnamectl #Check the current hostname
- Static hostname: Geeklp201
- Icon name: computer-vm
- Chassis: vm
- Machine ID: 77efa27de81d470883b5bb0ed04f468c
- Boot ID: fa62bd1c0f5e4e53a0691fb97971594f
- Virtualization: vmware
- Operating System: CentOS Linux 7 (Core)
- CPE OS Name: cpe:/o:centos:centos:7
- Kernel: Linux 3.10.0-693.el7.x86_64
- Architecture: x86-64
- [root@Geeklp201 ~]# hostnamectl set-hostname geeklp --static
- [root@Geeklp201 ~]# hostnamectl status
- Static hostname: geeklp
- Pretty hostname: Geeklp201
- Icon name: computer-vm
- Chassis: vm
- Machine ID: 77efa27de81d470883b5bb0ed04f468c
- Boot ID: fa62bd1c0f5e4e53a0691fb97971594f
- Virtualization: vmware
- Operating System: CentOS Linux 7 (Core)
- CPE OS Name: cpe:/o:centos:centos:7
- Kernel: Linux 3.10.0-693.el7.x86_64
- Architecture: x86-64
Method Two
The hostname is modified by modifying the file /etc/hostname. Replace the content of the file with the host name you want and restart.
Method three
You can also enter the graphical interface through nmtui to modify the host name. Move the cursor to the "Set System Host Name" menu by using the up and down keys of the keyboard, and press the Enter key.
At this point, the "Set Host Name" tab appears on the screen, enter the host name to be set, move the cursor to "OK" by the keyboard direction keys, and press the Enter key to confirm to complete the modification of the host name.