centos6修改hostname
#查看当前的hostnmae
[root@localhost ~]# hostname
localhost
#编辑network文件修改hostname行(重启生效)
[root@localhost ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=test
#设置当前的hostname(立即生效)
[root@localhost ~]# hostname test
# 编辑hosts文件,给127.0.0.1添加hostname
[root@localhost ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 test
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
centos7修改hostname
[root@localhost ~]# hostnamectl set-hostname test
#编辑下hosts文件, 给127.0.0.1添加hostname
[root@localhost ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 test
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6