| 用途 | 主机名与基础信息管理 |
|---|---|
| 语法 | hostnamectl [set-hostname 名称] |
| 相关 | /etc/hostname、/etc/hosts) |
查看与修改
查看与修改
hostnamectl
# Static hostname / Operating System / Kernel / Virtualization
sudo hostnamectl set-hostname web01.example.com
hostnamectl status
# 别忘了 hosts 里补一行,避免本地解析问题
grep -q web01 /etc/hosts || echo '127.0.0.1 web01.example.com web01' | sudo tee -a /etc/hosts改主机名后依赖主机名的服务(邮件、集群、监控)要同步更新;有配置管理平台的走平台改。