Centos 修改主机名称

2018-03-02 08:27:19来源:cnblogs.com作者:莫忘丶初心人点击

分享

 Centos 配置主机名称:

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

[[email protected]~]# 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修改主机名的方法

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

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

[[email protected] ~]# hostnamectl set-hostname [dch_mastar]          //修改临时主机名(立即生效)[[email protected]_mastar ~]# hostnamectl --static set-hostname dch_mastar          //修改永久主机名(立即生效)[[email protected]_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文件名

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

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

相关文章

    无相关信息

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台