Centos7中提供了设置主机名的工具 hostnamectl
hostname有三种状态 static(永久) transient(瞬态) pretty (灵活)
查看主机名状态
[oracle@hadoop ~]$ hostnamectl status Static hostname: hadoop Icon name: computer-vm Chassis: vm Machine ID: 52f2b03b2afb46be8b195895d9025dd3 Boot ID: e948f0f5e7524fb38c56f36dfbe4abb7 Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-514.2.2.el7.x86_64 Architecture: x86-64
设置主机名为centos7(瞬态)
[oracle@hadoop ~]$ hostnamectl --transient set-hostname centos7
设置主机名为centos7(永久)
[oracle@hadoop ~]$ hostnamectl --static set-hostname centos7