-h --help Show this help --version Show package version --no-ask-password Do not prompt for password -H --host=[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container --transient Only set transient hostname --static Only set static hostname --pretty Only set pretty hostname
Commands: status Show current hostname settings set-hostname NAME Set system hostname set-icon-name NAME Set icon name for host set-chassis NAME Set chassis type for host set-deployment NAME Set deployment environment for host set-location NAME Set location for host
查看主机名
1 2 3 4 5 6 7 8 9 10 11
[root@slions_pc1 ~]# hostnamectl Static hostname: slions_pc1 Icon name: computer-vm Chassis: vm Machine ID: 72c6db2a36e54cc584626da0118ed9ca Boot ID: 2cbdd44b889d40b29f932e9462e8ec15 Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-957.el7.x86_64 Architecture: x86-64
[root@slions_pc1 ~]# hostnamectl set-hostname "slions1 slions2" [root@slions_pc1 ~]# hostnamectl status Static hostname: slions1slions2 Pretty hostname: slions1 slions2 Icon name: computer-vm Chassis: vm Machine ID: 72c6db2a36e54cc584626da0118ed9ca Boot ID: 2cbdd44b889d40b29f932e9462e8ec15 Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-957.el7.x86_64 Architecture: x86-64
pretty hostname已经改变,且static hostname是它的”简化版”。
修改某种类型的主机名
1 2 3 4 5 6 7
hostnamectl set-hostname NAME --static hostnamectl set-hostname NAME --transient hostnamectl set-hostname NAME --pretty # 还可以同时修改两种 hostnamectl set-hostname NAME --static --transient hostnamectl set-hostname NAME --static --pretty hostnamectl set-hostname NAME --transient --pretty
修改、查看远程主机的主机名
使用”-H”或”–host”选项。连接基于SSH。
1 2
hostnamectl -H [USER@]HOST set-hostname NAME hostnamectl -H [USER@]HOST status