Change Hostname using Hostnamectl
The latest operating systems (Eg: Ubuntu 18.04, 16.04, Debian 9/8) running with systemd uses hostnamectl command to manage computer hostname. You can change the hostname of Linux system using the following command. For example, you need to set computer hostname to webhost1. This will update /etc/hostname file on your system and load in the current environment. But you still need hostname binding with localhost IP. Edit /etc/hosts file to bind new hostname with localhost IP address. Now, Execute the below command to find current hostname set for your system.
Change Hostname Manually
You also use older way to change the hostname of the system manually by editing configuration files directly. To change hostname first edit /etc/hostname file and write your hostname there. /etc/hostname: After editing the file, you can also set the hostname for the current session to avoid system reboot. After that edit /etc/hosts file to bind new hostname with localhost IP address.