文章目录
1、查看当前主机名
[root@localhost ~]# hostname
localhost
[root@localhost ~]# hostnamectl
Static hostname: localhost
Icon name: computer
Chassis: n/a
Machine ID: 9e3877e4c127481eb6f1170fcf1be9e2
Boot ID: 52bc258264a643e788afc8b0afc261d7
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-123.el7.x86_64
Architecture: x86_64
[root@localhost ~]#
2、临时修改主机名
[root@localhost ~]# hostname local //临时修改主机名,关机后失效
[root@localhost ~]# hostname
local
[root@localhost ~]#
3、永久修改主机名
[root@localhost ~]# vim /etc/hostname //vim进入主机配置文件
localhost //删除旧主机名,输入新主机名,
:wq //esc后,:wq保存退出
[root@localhost ~]# reboot