How can I set machine hostname on a Linux machine using NMCLI?. Is it possible to change hostname on CentOS/RHEL/Fedora/Ubuntu/Debian/RHCOS/FCOS machine using nmcli Network management tool?. The answer to both questions is YES!. You can change or set hostname of a Linux system running Network Manager using nmcli. Here is how to..

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/04/echo/set-linux-machine-hostname-with-nmcli.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" src="data:image/svg xml,”>

Check if the hostname is already configured with other tools such as hostnamectl or manually editing hostname files.

$ hostnamectl
   Static hostname: n/a
Transient hostname: node01.ocp.example.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 3f47d43533514bb6bcc03d51b7468459
           Boot ID: c4d5933c9cdc45bf8a77a8024e3c19f3
    Virtualization: vmware
  Operating System: Red Hat Enterprise Linux CoreOS 43.81.202002170853.0 (Ootpa)
            Kernel: Linux 4.18.0-147.5.1.el8_1.x86_64
      Architecture: x86-64

I noted on Red Hat CoreOS that when you set hostname with hostnamectl, it disappears upon reboot. But when you use nmcli, the hostname persists across system reboots. So this is how you can set hostname using nmcli.

$ sudo nmcli general hostname 

In my example, I’ll run:

$ sudo nmcli general hostname node01.ocp.example.com

Confirm that the hostname has been set correctly:

$ nmcli general hostname 
node01.ocp.example.com

There you have it.. You have successfully set or changed hostname on a Linux machine with ncmli command line tool.

More on Linux:

How To run Arch Linux on Windows WSL

Arch Linux Easy and Fast Installation With Archfi

Setup Maltrail Malicious Traffic Detection System on Linux

Install Nessus vulnerability Scanner on Kali Linux 2020.x

Install Metasploit Framework on Kali Linux 2020.x