Centos修改主机名

1.查看主机名

查看主机名相关的设置

[root@VM_189_104_centos ~]#hostnamectl
Static hostname: VM_189_104_centos
Icon name: computer-vm
Chassis: vm
Machine ID: c28d40cbc8e3adcb4e32d9779a77b39e
Boot ID: 2318af805a4e4ea1a59f35ce9187efe4
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-862.el7.x86_64
Architecture: x86-64

[root@VM_189_104_centos ~]#hostnamectl status
Static hostname: VM_189_104_centos
Icon name: computer-vm
Chassis: vm
Machine ID: c28d40cbc8e3adcb4e32d9779a77b39e
Boot ID: 2318af805a4e4ea1a59f35ce9187efe4
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-862.el7.x86_64
Architecture: x86-64

只查看静态、瞬态或灵活主机名,分别使用“--static”,“--transient”或“--pretty”选项。

[root@VM_189_104_centos ~]#hostnamectl --static
VM_189_104_centos
[root@VM_189_104_centos ~]#hostnamectl --transient
VM_189_104_centos
[root@VM_189_104_centos ~]#hostnamectl --pretty
VM_189_104_centos

2.同时修改所有三个主机名:静态、瞬态和灵活主机名

hostnamectl set-hostname VM189104centos

[root@VM_189_104_centos ~]# hostnamectl status
Static hostname: vm189104centos
Pretty hostname: VM189104centos
Icon name: computer-vm
Chassis: vm
Machine ID: c28d40cbc8e3adcb4e32d9779a77b39e
Boot ID: 2318af805a4e4ea1a59f35ce9187efe4
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-862.el7.x86_64
Architecture: x86-64

3.修改/etc/hosts文件

以上修改只会修改/etc/hostname文件,不会修改/etc/hosts文件,/etc/hosts文件我们需要手动修改

vim /etc/hosts
hosts文件

4.重启系统

reboot -f

参考如何在CentOS 7上修改主机名hostname

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容