Modify hostname under CentOS 7

View the current hostname

Method 1

[root@localhost ~]# hostname
localhost.localdomain

Method 2: centos7 and above

[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

Temporary host name change

Temporary changes that do not take effect after restarting the server.

[root@localhost ~]# hostname 7ix.net 
[root@localhost ~]# hostname
7ix.net 

Check the IP address corresponding to this machine name.

[root@localhost ~]# hostname -i
192.168.0.1

Permanent host name change

Method 1: Use the hostnamectl command, contos7 and above are applicable

[root@localhost ~]# hostnamectl set-hostname 7ix.net

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

[root@localhost ~]# vi /etc/hostname
7ix.net

Note: Both of the above permanent modification methods require a reboot of the machine to take effect.

[root@localhost ~]# reboot

Leave a Reply