1.查看主机名
查看主机名相关的设置
[root@VM_189_104_centos ~]#hostnamectl
Static hostname: VM_189_104_centos
Icon name: computer-vm
Chassis: vm
Machine ID: c28d40cbc8e3adcb4e32d9779a77b39e
Boot ID: 2318af805a4e4ea1a59f35ce9187efe4
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-862.el7.x86_64
Architecture: x86-64
[root@VM_189_104_centos ~]#hostnamectl status
Static hostname: VM_189_104_centos
Icon name: computer-vm
Chassis: vm
Machine ID: c28d40cbc8e3adcb4e32d9779a77b39e
Boot ID: 2318af805a4e4ea1a59f35ce9187efe4
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-862.el7.x86_64
Architecture: x86-64
只查看静态、瞬态或灵活主机名,分别使用“--static”,“--transient”或“--pretty”选项。
[root@VM_189_104_centos ~]#hostnamectl --static
VM_189_104_centos
[root@VM_189_104_centos ~]#hostnamectl --transient
VM_189_104_centos
[root@VM_189_104_centos ~]#hostnamectl --pretty
VM_189_104_centos
2.同时修改所有三个主机名:静态、瞬态和灵活主机名
hostnamectl set-hostname VM189104centos
[root@VM_189_104_centos ~]# hostnamectl status
Static hostname: vm189104centos
Pretty hostname: VM189104centos
Icon name: computer-vm
Chassis: vm
Machine ID: c28d40cbc8e3adcb4e32d9779a77b39e
Boot ID: 2318af805a4e4ea1a59f35ce9187efe4
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-862.el7.x86_64
Architecture: x86-64
3.修改/etc/hosts文件
以上修改只会修改/etc/hostname文件,不会修改/etc/hosts文件,/etc/hosts文件我们需要手动修改
vim /etc/hosts
4.重启系统
reboot -f