最近想修改Centos7的hostname, 可是如果直接修改hostname文件不生效,今天查了查原来centos有几种hostname.
hostnamectl 控制整个系统的hostname,推荐使用
nmtul 使用text ui 控制
nmtcli 可以用但是不推荐使用
[root@willweb ~]# hostnamectl status
Static hostname: willweb
Icon name: computer-vm
Chassis: vm
Machine ID: f9d400c5e1e8c3a8209e990d887d4ac1
Boot ID: dd7be45d652849dcb82493c286c69dbf
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
[root@willweb ~]# hostname
willweb
[root@willweb ~]# hostnamectl
Static hostname: willweb
Icon name: computer-vm
Chassis: vm
Machine ID: f9d400c5e1e8c3a8209e990d887d4ac1
Boot ID: dd7be45d652849dcb82493c286c69dbf
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
[root@willweb ~]# hostnamectl status
Static hostname: willweb
Icon name: computer-vm
Chassis: vm
Machine ID: f9d400c5e1e8c3a8209e990d887d4ac1
Boot ID: dd7be45d652849dcb82493c286c69dbf
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
使用命令如下
# hostnamectl set-hostname Your-New-Host-Name-Here
# hostnamectl set-hostname "Your New Host Name Here" --pretty
# hostnamectl set-hostname Your-New-Host-Name-Here --static
# hostnamectl set-hostname Your-New-Host-Name-Here --transient
远程设置hostname
ssh root@server-ip-here hostnamectl set-hostname server1
hostnamectl set-hostname server1 -H root@192.168.1.42