Centos 修改主机名称,centos主机名称


 Centos 配置主机名称:

 

1.首先查询一下当前的主机名称

[root@localhost~]# hostnamectl status
   Static hostname: ******          //永久主机名
   Pretty hostname: [******]          //临时主机名
         Icon name: computer-server
           Chassis: server
        Machine ID: c141adc566834695aa95ee72f48a48d4
           Boot ID: 868413124b9c4bdb8f0f8831be9a82d9
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-514.el7.x86_64
      Architecture: x86-64

 

2.Centos 6修改主机名的方法

[root@localhost ~]# vim /etc/sysconfig/network        //# 编辑network文件修改hostname行(重启生效)
[root@localhost ~]# cat /etc/sysconfig/network
#
Created by anaconda
HOSTNAME=
dch_mastar

 

3.Centos 7修改主机名的方法

[root@localhost ~]# hostnamectl set-hostname [dch_mastar]          //修改临时主机名(立即生效)
[root@dch_mastar ~]# hostnamectl --static set-hostname dch_mastar          //修改永久主机名(立即生效)
[root@dch_mastar ~]# hostnamectl status
   Static hostname: dch_mastar
   Pretty hostname: [dch_mastar]
         Icon name: computer-server
           Chassis: server
        Machine ID: c141adc566834695aa95ee72f48a48d4
           Boot ID: 868413124b9c4bdb8f0f8831be9a82d9
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-514.el7.x86_64
      Architecture: x86-64

 

4.配置/etc/hosts文件名

[root@dch_mastar ~]# vim /etc/hosts           //为hosts文件127.0.0.1添加hostname
[root@dch_mastar ~]# cat /etc/hosts 
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 dch_mastar 
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

 

5.修改完主机名后如果[root@localhost ~]#这一部分不刷新的话请关闭命令窗口重启命令窗口。Centos 6 和 7一样

 

相关内容