CentOS 7 下修改主机名

1.查看当前的主机名

方法1:

1

2

[root@localhost ~]# hostname

localhost.localdomain

方法2:centos7及以上版本

1

2

3

4

5

6

7

8

9

10

11

[root@localhost ~]# hostnamectl

   Static hostname: localhost.localdomain

         Icon name: computer-vm

           Chassis: vm

        Machine ID: e147b422673549a3b4fda77127bd4bcc

           Boot ID: 0fdf38042c5e43c28ef3f1ec5cba182a

    Virtualization: oracle

  Operating System: CentOS Linux 7 (Core)

       CPE OS Name: cpe:/o:centos:centos:7

            Kernel: Linux 3.10.0-327.4.5.el7.x86_64

      Architecture: x86-64

2.临时修改主机名

临时修改,重启服务器后就不生效了

1

2

3

[root@localhost ~]# hostname pythontab.com 

[root@localhost ~]# hostname

pythontab.com

查看本机器名对应的ip地址

1

2

[root@localhost ~]# hostname -i

192.168.33.100

3.永久修改主机名

需要修改以下两个配置文件

1、方法一: 使用hostnamectl命令, contos7及以上版本适用

1

[root@localhost ~]# hostnamectl set-hostname pythontab.com

2、方法二:修改配置文件 /etc/hostname 保存退出

1

2

[root@localhost ~]# vi /etc/hostname

pythontab.com

注意:上面两种永久修改方法都需要重启机器后生效

1

[root@localhost ~]# reboot

猜你喜欢

转载自blog.csdn.net/kexin178/article/details/112917224