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:
nano /etc/hostname
For example:
1.2.3.4 new_hostname.com
On RHEL/CentOS based systems that use init, the hostname is changed by modifying:
nano /etc/sysconfig/network
For example:
HOSTNAME="new_hostname.com"
You can check the hostname using the next command:
hostname