命令 hostnamectl
描述 Control the system hostname 设置主机名
用法 1 hostnamectl [OPTIONS...] COMMAND ...
选项 1 2 3 4 5 6 7 8 9 10 11 12 Options: --host=[USER@]HOST 操作远程主机,需要输入密码 Commands: status 显示当前主机名设置,默认命令 set-hostname NAME 设置主机名 set-icon-name NAME 设置主机图标名称 set-chassis NAME 设置主机类型 set-deployment NAME 设置主机的部署环境,可自定义,如dev,prod set-location NAME 设置主机位置,可自定义,如bj-lt chassis类型可选参数: container,embedded,laptop,tablet,watch,desktop,handset,server,vm
注意 更改主机名推荐使用该命令,建议更改后重启机器
示例 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 $ hostnamectl Static hostname: centos7 Transient hostname: node01 Icon name: computer-vm Chassis: vm Machine ID: 957df69236a74f3fa2537f55e219141b Boot ID: 0ff000e74e9b4e57a05da6e22e3d4291 Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-1160.11.1.el7.x86_64 Architecture: x86-64 $ more /etc/hostname centos7 $ hostnamectl set-hostname node01 $ more /etc/hostname node01 $ hostnamectl set-chassis server $ hostnamectl set-deployment dev $ hostnamectl set-location bj $ hostnamectl Static hostname: node01 Icon name: iconname Chassis: server Deployment: dev Location: bj $ hostnamectl set-deployment ''