centos modify hostname


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.

[html]  view plain copy  
  1. [root@Geeklp201 ~]# hostnamectl #Check the current hostname  
  2.    Static hostname: Geeklp201  
  3.          Icon name: computer-vm  
  4.            Chassis: vm  
  5.         Machine ID: 77efa27de81d470883b5bb0ed04f468c  
  6.            Boot ID: fa62bd1c0f5e4e53a0691fb97971594f  
  7.     Virtualization: vmware  
  8.   Operating System: CentOS Linux 7 (Core)  
  9.        CPE OS Name: cpe:/o:centos:centos:7  
  10.             Kernel: Linux 3.10.0-693.el7.x86_64  
  11.       Architecture: x86-64  
  12. [root@Geeklp201 ~]# hostnamectl set-hostname geeklp --static  
  13. [root@Geeklp201 ~]# hostnamectl status  
  14.    Static hostname: geeklp  
  15.    Pretty hostname: Geeklp201  
  16.          Icon name: computer-vm  
  17.            Chassis: vm  
  18.         Machine ID: 77efa27de81d470883b5bb0ed04f468c  
  19.            Boot ID: fa62bd1c0f5e4e53a0691fb97971594f  
  20.     Virtualization: vmware  
  21.   Operating System: CentOS Linux 7 (Core)  
  22.        CPE OS Name: cpe:/o:centos:centos:7  
  23.             Kernel: Linux 3.10.0-693.el7.x86_64  
  24.       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.

Guess you like

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