天天看点

Linux修改主机名Linux修改主机名

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] ~]# 
           

继续阅读