This article will focus about how to change the host name of an operating system. As it exist in the title of the article itself, the execution is in Linux CentOS 7. The process for changing the host name of an operating system is not too hard. Just execute the correct and suitable command in the command line interface. The command execution itself is possible in the shell command prompt available in the operating system. Just access the command line interface and execute the command.
Using hostnamectl to change the host name of an operating system in Linux CentOS 7
A command available to change the host name of an operating system in Linux CentOS 7 is ‘hostnamectl’. Just type the following pattern command to change it as follows :
For an example :
[root@localhost ~]# hostnamectl set-hostname myhostname [root@localhost ~]# hostname myhostname [root@localhost ~]# hostnamectl Static hostname: myhostname Icon name: computer-vm Chassis: vm Machine ID: 1e6e9c9002cd9609bf851a132b8bf805 Boot ID: 0c3a5b6f181c46a5bd439415d6bfac0b Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-693.11.1.el7.x86_64 Architecture: x86-64 [root@localhost ~]#
In the above output, the hostname part in the command prompt shell information is not changing at all after the command execution. Although according to the command ‘hostname’ and ‘hostnamectl’ for displaying the host name is changed. But actually, if the command line interface is stop and then after that start to execute the command line interface again, the host name part will change accordingly. It is also the case with disconnecting from the command line and reconnect it again by any remote means to the machine. It will present the command line interface with the part of the command prompt shell informing the new host name.