方法1:修改配置文件(/etc/hostname)

#vim /etc/hostname
centos7

方案2:使用hostnamectl的命令
[cqs@centos7 ~]$hostnamectl status
Static hostname: centos7
Icon name: computer-vm
Chassis: vm
Machine ID: 7c14d614a12042b8ad158b3f4a2b3c10
Boot ID: 04eb3c6a16ff442f871a4463dfdac607
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-514.26.1.el7.x86_64
Architecture: x86-64
[cqs@centos7 ~]$ cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
[cqs@centos7 ~]$ cat /etc/hostname
centos7
[cqs@centos7 ~]$ hostname
centos7
[cqs@centos7 ~]$hostnamectl set-hostname centos7
备注:主机名成功修改后,/etc/hostname文件内容更新为最新主机名,但是/etc/hosts文件中主机名不变,需要手工修改。

方案三:使用nmtui终端工具
打开图形界面进行修改
#nmtui
NetworkManag--设定系统主机名-->主机名-->centos7