Change Hostname using Hostnamectl

The latest Fedora and CentOS operating systems 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 workstation1. This will update /etc/hostname file on your system and load in the current environment. But you still need hostname binding with localhost IP. Also edit /etc/hosts file and add new hostname with localhost IP address like: 127.0.1.1 workstation1. 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.