以前的 Redhat 及 CentOS 要更改 hostname 可以修改 /etc/sysconfig/network, 或用 hostname 指令设定。Centos 7 及 CentOS 8 改用了新的方法, 现在是用 hostnamectl 指令修改系统的 hostname。
检查主机 hostname:
# hostnamectl
会列出目前使用的 hostname, 要修也是使用 hostnamectl 指令:
# hostnamectl set-hostname new_hostname
上面的 new_hostname 是新 hostname, 设定好后可以再用 hostnamectl 检一是否生效。