前言
安裝了CentOS7,發現按照以前修改文件/etc/sysconfig/network HOSTNAME字段主機名的方式不生效了,查資料發現可以使用hostnamectl命令
用途
Control the system hostname
用法
hostnamectl [options] {command}
常用選項
--static
the static hostname which is used to initialize the kernel hostname at boot
--transient
he transient hostname which is a default received from network configuration.
--pretty
the high-level "pretty" hostname which might include all kinds of special characters
實踐
顯示主機名和相關信息
[root@vm-node1 ~]# hostnamectl Static hostname: vm-node1 Icon name: computer-vm Chassis: vm Machine ID: 97a20c207e324ad78ef902d44d77affd Boot ID: 3663cc8de26b442c9bb84c4a07f4955a Virtualization: oracle Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-693.el7.x86_64 Architecture: x86-64
設置主機名
[root@vm-node1 ~]# hostnamectl --static set-hostname vm-node1
參考資料
【1】man hostnamectl