CentOS6
1.查看主机名
[root@foundation42 ~]# vim /etc/hostname # 真机里只能这样修改
1 foundation42.ilt.example.com
[root@foundation42 ~]# hostname # 查看主机名
foundation42.ilt.example.com
CentOS7
1.查看全部三种主机名
[root@zhao ~]# hostnamectl status
Static hostname: zhao
Icon name: computer-vm
Chassis: vm
Machine ID: 3b31428930b740778c7295f35770197e
Boot ID: 15a0d7a403f8497eac4c15c65308f8ab
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1062.el7.x86_64
Architecture: x86-64
2.修改主机名
方法1:临时有效
**[root@zhao ~]# hostname 123**
[root@zhao ~]# hostnamectl status
Static hostname: zhao
Transient hostname: 123(只有这瞬态名字改了)
Icon name: computer-vm
Chassis: vm
Machine ID: 3b31428930b740778c7295f35770197e
Boot ID: 15a0d7a403f8497eac4c15c65308f8ab
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1062.el7.x86_64
Architecture: x86-64
方法2:永久生效
[root@zzw ~]# hostnamectl set-hostname zhao
[root@zzw ~]# hostname
zhao
[root@zzw ~]# reboot
[root@zhao ~]#