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..

set linux machine hostname with nmcli

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 <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

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!


As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.

LEAVE A REPLY

Please enter your comment!
Please enter your name here