天天看点

CentOS6,CentOS7修改主机名

CentOS6

1.查看主机名

[[email protected] ~]# vim /etc/hostname # 真机里只能这样修改

1 foundation42.ilt.example.com

[[email protected] ~]# hostname # 查看主机名

foundation42.ilt.example.com

CentOS7

1.查看全部三种主机名

[[email protected] ~]# 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:临时有效

**[[email protected] ~]# hostname 123**
           

[[email protected] ~]# 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:永久生效

[[email protected] ~]# hostnamectl set-hostname zhao

[[email protected] ~]# hostname

zhao

[[email protected] ~]# reboot

[[email protected] ~]#

继续阅读