Linux command to rename server name

What command I need to type to rename server name in Linux? Is it hostname? I am using CentOS 8 with EC2 server in AWS cloud.

For CentOS8 or any modern Linux distro use the hostnamectl command to change or view server name.

View server name

hostnamectl
   Static hostname: nixcraft-wks01
         Icon name: computer-laptop
           Chassis: laptop
        Machine ID: 7e163c7b219a4bed8968e482b3c3fa30
           Boot ID: d33e824fc8a3414392c020a2b17e4b82
  Operating System: Ubuntu 20.04 LTS
            Kernel: Linux 5.4.0-40-generic
      Architecture: x86-64

Change / rename server name

We can set the Linux system/server hostname to FOOBAR using the syntax:

sudo hostnamectl set-hostname FOOBAR
hostnamectl

See the following tutorial:


Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki