Linux修改主機名
伺服器版本: Centos 7.2 參考
臨時修改主機名
hostname 檢視目前系統主機名,知道目前主機名
hostname 要修改的主機名
[[email protected] ~]# hostname masteryee-one
[[email protected] ~]# hostname
masteryee-one
永久修改主機名
當然在centos7特地添加了 hostnamectl 指令檢視,修改主機名
[[email protected] ~]# hostnamectl
Static hostname: i-9s7be0le
Transient hostname: masteryee-one
Icon name: computer-vm
Chassis: vm
Machine ID: 668a8a15b473b53db8a06eba66cbc862
Boot ID: b7a67567d7624913a7b25cfac8cc6bf5
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.4.5.el7.x86_64
Architecture: x86-64
使用 hostnamectl set-hostname 指令修改主機名,可永久生效:
[[email protected] ~]# hostnamectl set-hostname masteryee-one
[[email protected] ~]# hostname
masteryee-one
[[email protected] ~]# hostnamectl
Static hostname: masteryee-one
Icon name: computer-vm
Chassis: vm
Machine ID: 668a8a15b473b53db8a06eba66cbc862
Boot ID: b7a67567d7624913a7b25cfac8cc6bf5
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.4.5.el7.x86_64
Architecture: x86-64
[[email protected] ~]#