Modify the hostname under CentOS 7

1. View the current hostname

method 1:

1

2

[root@localhost ~]# hostname

localhost.localdomain

Method 2: centos7 and above

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. Temporarily modify the host name

Temporary modification will not take effect after restarting the server

1

2

3

[root@localhost ~]# hostname pythontab.com 

[root@localhost ~]# hostname

pythontab.com

View the IP address corresponding to the machine name

1

2

[root@localhost ~]# hostname -i

192.168.33.100

3. Permanently modify the host name

Need to modify the following two configuration files

1. Method 1: Use hostnamectl command, applicable for contos7 and above

1

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

2. Method 2: Modify the configuration file /etc/hostname, save and exit

1

2

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

pythontab.com

Note: The above two permanent modification methods need to restart the machine to take effect

1

[root@localhost ~]# reboot

 

Guess you like

Origin blog.csdn.net/kexin178/article/details/112917224