CentOS7修改主机名
CentOS7修改主机名
查看当前的主机名
- 第一种方法
[root@localhost ~]# hostname
localhost.localdomain
- 第二种方法
[root@localhost ~]# hostnamectl
Static hostname: localhost.localdomain
Icon name: computer-vm
Chassis: vm
Machine ID: 90300023da1f4b85b4c7cd89dbb4f1cc
Boot ID: c054f20e33d74e1a8ec29557885c75c6
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-957.el7.x86_64
Architecture: x86-64
修改主机名称
[root@localhost ~]# hostnamectl set-hostname study
修改/etc/hosts
127.0.0.1 study.linux.com study
::1 study.linux.com study
验证是否修改成功
重新启动服务器,使用hostname命令和hostnamectl命令查看主机名
[root@study ~]# hostname
study
[root@study ~]# hostname -a
study.linux.com study.linux.com
[root@study ~]# hostnamectl
Static hostname: study
Icon name: computer-vm
Chassis: vm
Machine ID: 90300023da1f4b85b4c7cd89dbb4f1cc
Boot ID: c054f20e33d74e1a8ec29557885c75c6
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-957.el7.x86_64
Architecture: x86-64