Bootstrap FreeKB - Linux Commands - hostnamectl
Linux Commands - hostnamectl

Updated:   |  Linux Commands articles

There are two similar commands that can be used to list or update a Linux systems hostname.

The hostnamectl command without any options can be used to view the hostname of the system.

~]$ hostnamectl
   Static hostname: server1.example.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: c412e00d88a746d884ab2d375aa9cfab
           Boot ID: 574b87676e9545f2b6d7401ad1a3a2d7
    Virtualization: vmware
  Operating System: Red Hat Enterprise Linux
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.9:GA:server
            Kernel: Linux 3.10.0-1160.108.1.el7.x86_64
      Architecture: x86-64

 

The hostnamectl status command should return the same exact output.

~]$ hostnamectl status
   Static hostname: server1.example.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: c412e00d88a746d884ab2d375aa9cfab
           Boot ID: 574b87676e9545f2b6d7401ad1a3a2d7
    Virtualization: vmware
  Operating System: Red Hat Enterprise Linux
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.9:GA:server
            Kernel: Linux 3.10.0-1160.108.1.el7.x86_64
      Architecture: x86-64

 

If a Debian family distribution is being used, the hostname command reads the contents of the /etc/hostname file.

~]# cat /etc/hostname
server1.example.com

 

If a Red Hat family distribution is being used, the hostname command reads the contents of the /etc/hostname or /etc/sysconfig/network file.

~]# cat /etc/hostname
server1.example.com

~]# cat /etc/sysconfig/network
HOSTNAME=server1.example.com

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter c68965 in the box below so that we can be sure you are a human.