Modify the Host Name and Centos Host Name
Centos configuration Host Name:
1. First query the current host name
[Root @ localhost ~] # Hostnamectl status Static hostname: ****** // permanent host name Pretty hostname: [*******] // temporary host name Icon name: computer-server Chassis: server Machine ID: c141adc56682135aa95ee72f48a48d4 Boot ID: running Operating System: CentOS Linux 7 (Core) cpe OS Name: cpe:/o: centos: 7 Kernel: Linux 3.10.0-514. el7.x86 _ 64 Architecture: x86-64
2. How to modify the host name in Centos 6
[Root @ localhost ~] # Vim/etc/sysconfig/network // # edit the hostname line of the network file (restart to take effect)
[Root @ localhost ~] # Cat/etc/sysconfig/network
# Created by anaconda
HOSTNAME = dch_mastar
3. How to modify the host name in Centos 7
[Root @ localhost ~] # Hostnamectl set-hostname [dch_mastar] // modify the temporary host name (effective immediately) [root @ dch_mastar ~] # Hostnamectl -- static set-hostname dch_mastar // modify the permanent host name (effective immediately) [root @ dch_mastar ~] # Hostnamectl status Static hostname: dch_mastar Pretty hostname: [dch_mastar] Icon name: computer-server Chassis: server Machine ID: your Boot ID: your Operating System: CentOS Linux 7 (Core) cpe OS Name: cpe:/o: centos: 7 Kernel: Linux 3.10.0-514. el7.x86 _ 64 Architecture: x86-64
4. Configure the/etc/hosts file name
[Root @ dch_mastar ~] # Vim/etc/hosts // Add the hostname [root @ dch_mastar ~] for the hosts file 127.0.0.1 # Cat/etc/hosts 127.0.0.1 localhost. localdomain localhost4 localhost4.localdomain4 dch_mastar: 1 localhost. localdomain localhost6 localhost6.localdomain6
5. After modifying the host name, if [root @ localhost ~] # If this part is not refreshed, close the command window and restart the command window. Same as Centos 6 and 7