Change your hostname in Linux

How to Properly rename a Linux host

Using hostnamectl

hostnamectl is part of systemd. It provides a standardized way for setting a server's hostname via API.

hostnamectl

This will produce the output looking like this:

   Static hostname: node3
         Icon name: computer-vm
           Chassis: vm
        Machine ID: fb85d4e701f547cf96a8a1c71e1424fa
           Boot ID: 5179c00054b540e0ad501a69dc41255c
    Virtualization: vmware
  Operating System: Ubuntu 20.04.1 LTS
            Kernel: Linux 5.4.0-53-generic
      Architecture: arm64

To set

hostnamectl set-hostname 'prod-node'