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=master
3.Centos 7修改主机名的方法
[root@localhost ~]# hostnamectl set-hostname [master] //修改临时主机名(立即生效)
[root@master ~]# hostnamectl --static set-hostname master //修改永久主机名(立即生效)
[root@master ~]# hostnamectl status
Static hostname: master
Pretty hostname: [master]
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@master ~]# vim /etc/hosts //为hosts文件127.0.0.1添加hostname
[root@master ~]# cat /etc/hosts
内网IP master
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
5.修改完主机名后如果[root@localhost ~]#这一部分不刷新的话请关闭命令窗口重启命令窗口。Centos 6 和 7一样