Newer version of different Linux distributions such as latest Ubuntu, Debian, CentOS, Fedora, RedHat, etc. comes with systemd, a system and service manager that provides a hostnamectl command to manage hostnames in Linux.
To set system hostname on SystemD based distributions, we will use hostnamectl command as shown:
hostnamectl set-hostname new_hostname.com
For Older Linux distributions, which uses SysVinit in short init, can have their hostnames changed by simply editing the hostname file located in:
On RHEL/CentOS based systems that use init, the hostname is changed by modifying:
You can check the hostname using the next command: