Centos7修改主机名
程序员文章站
2024-03-14 13:54:52
...
Centos7中提供了设置主机名的工具 hostnamectl
hostname有三种状态
- static(静态/”永久“)
- transient(瞬态)
- pretty (灵活)
1、查看主机名状态
[[email protected] ~]# hostnamectl status
Static hostname: localhost.localdomain
Icon name: computer-desktop
Chassis: desktop
Machine ID: 83232ce91ee743d299db565241c6795c
Boot ID: 42563b996e1948f7904b9b2ee4e19d9c
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
2、设置主机名为master(瞬态)
[[email protected] ~]# hostnamectl --transient set-hostname master
3、设置主机名为master(永久)
[[email protected] ~]# hostnamectl --static set-hostname master
reboot重启生效
修改了静态主机名,/ETC/HOSTNAME 将被自动更新。/ETC/HOSTS 下的主机名需要手动更新
转载于:https://www.jianshu.com/p/a3bf9f359640