梦想吧

249 分类: 随便说说

Centos6与Centos7修改主机名的方法

1、centos6下修改hostname

[[email protected] ~]$ hostname                                              # 查看当前的hostnmae
centos6.magedu.com
[[email protected] ~]$ vim /etc/sysconfig/network                            # 编辑network文件修改hostname行(重启生效)
[[email protected] ~]$ cat /etc/sysconfig/network                            # 检查修改
NETWORKING=yes
HOSTNAME=mx8club-hk-a
[[email protected] ~]$ hostname mx8club-hk-a                          # 设置当前的hostname(立即生效)
[[email protected] ~]$ vim /etc/hosts                                        # 编辑hosts文件,给127.0.0.1添加hostname
[[email protected] ~]$ cat /etc/hosts                                        # 检查
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 centos66.magedu.com
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

2、centos7修改hostname

[[email protected] ~]$ hostnamectl set-hostname mx8club-hk-a             # 使用这个命令会立即生效且重启也生效
[[email protected] ~]$ hostname                                                 # 查看下
mx8club-hk-a
[[email protected] ~]$ vim /etc/hosts                                           # 编辑下hosts文件, 给127.0.0.1添加hostname
[[email protected] ~]$ cat /etc/hosts                                           # 检查
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 mx8club-hk-a
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

#Linux, Centos

作者: Jim

版权: 除特别声明,均采用BY-NC-SA 4.0许可协议,转载请表明出处

目录Content

评论