A.hostnamectl命令修改主机名
常用命令
1.查看状态
hostnamectl
[root@localhost xiongyingli]# hostnamectl
Static hostname: localhost.localdomain
Icon name: computer-laptop
Chassis: laptop
Machine ID: 02f44c77569d4c0a96da22d6a99a0eaa
Boot ID: e4e97476a171400c9f02c04a43242f79
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
或者
hostnamectl status
[root@localhost xiongyingli]# hostnamectl status
Static hostname: localhost.localdomain
Icon name: computer-laptop
Chassis: laptop
Machine ID: 02f44c77569d4c0a96da22d6a99a0eaa
Boot ID: e4e97476a171400c9f02c04a43242f79
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
2.修改主机名称
[root@localhost xiongyingli]# hostnamectl set-hostname centos7.hanhua.com
[root@localhost xiongyingli]# hostnamectl status
Static hostname: centos7.hanhua.com
Icon name: computer-laptop
Chassis: laptop
Machine ID: 02f44c77569d4c0a96da22d6a99a0eaa
Boot ID: e4e97476a171400c9f02c04a43242f79
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
B.编辑/etc/hosts文件修改主机名
常用命令
1.查看主机名
[root@localhost xiongyingli]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
2.修改主机名
root@localhost xiongyingli]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 centos7.hanhua.com
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6