Brief: This article describes you to how to find current hostname of the system. Also, how can you change the hostname of your Redhat based systems?
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.
sudo hostnamectl set-hostname 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:
Now, Execute the below command to find current hostname set for your system.
hostnamectl Static hostname: workstation1 Icon name: computer-vm Chassis: vm Machine ID: b669a2e70002461cac387ba87397c78b Boot ID: a0b60ab33f8e43aa9d04b9950f91ab6c Virtualization: oracle Operating System: Fedora 26 (Workstation Edition) CPE OS Name: cpe:/o:fedoraproject:fedora:26 Kernel: Linux 4.13.5-200.fc26.x86_64 Architecture: x86-64
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.
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.