这 系统名称又名主机名, 通常由系统管理员或系统构建在安装操作系统期间设置 admin. 但是,有时,我们可能需要根据需要更改服务器的主机名。
本指南将帮助您在 CentOS 8 / RHEL 8 中设置/更改主机名。
主机名可以是,
- 长度为 64 个字符
- 建议有 FQDN
- 由az、AZ、0-9、“-”、“_”和“.”组成只要
在 CentOS 8 / RHEL 8 中更改主机名
我们可以使用不同的方法更改主机名。
2. 使用 nmtui 工具
在更改主机名之前,让我们检查当前的主机名。
[root@localhost ~]# hostname
输出:
localhost.localdomain
hostnamectl 命令
主机名 用于在不重新启动系统的情况下更改主机名。
使用 hostnamectl 更改主机名,因为它比其他方法好得多,并且不需要更新内核以了解主机名的更改。
[root@localhost ~]# hostnamectl status
输出:
Static hostname: localhost.localdomain Icon name: computer-vm Chassis: vm Machine ID: a35862c3f73f451cbdf15fd2336fefcb Boot ID: 7e4c96cea89f40b8817d9a9cae1bc82d Virtualization: oracle Operating System: CentOS Linux 8 (Core) CPE OS Name: cpe:/o:centos:centos:8 Kernel: Linux 4.18.0-80.el8.x86_64 Architecture: x86-64
设置主机名。
[root@localhost ~]# hostnamectl set-hostname client.itzgeek.local
重新检查主机名(关闭会话并使用腻子或控制台打开一个新会话)
[root@client ~]# hostnamectl status
输出:
Static hostname: client.itzgeek.local Icon name: computer-vm Chassis: vm Machine ID: a35862c3f73f451cbdf15fd2336fefcb Boot ID: 7e4c96cea89f40b8817d9a9cae1bc82d Virtualization: oracle Operating System: CentOS Linux 8 (Core) CPE OS Name: cpe:/o:centos:centos:8 Kernel: Linux 4.18.0-80.el8.x86_64 Architecture: x86-64
或者
[root@client ~]# hostname
输出:
client.itzgeek.local
nmtui 工具
网络管理器工具(yum install -y NetworkManager-tui) 用于设置静态主机名 /etc/主机名 文件。
nmtui
选择设置主机名
设置主机名。
主机名已设置。
Exit 从工具。
使用以下命令检查主机名。
[root@localhost ~]# hostname client.itzgeek.local
[root@localhost ~]# cat /etc/hostname client.itzgeek.local
/etc/主机名文件
这种方法很简单,但需要重启服务器才能生效。
编辑 /etc/主机名 文件。
vi /etc/hostname
添加主机名,如下所示。
client.itzgeek.local
重新启动机器以更新有关主机名更改的内核。
reboot
结论
就这样。 请在评论部分分享您的反馈。