Hostname is the program that is used to either set or display the current host, domain or node name of the system. These names are used by many of the networking programs to identify the machine.
In this article I will show how you can change your hostname on Fedora and CentOS systems.
In the latest Fedora and CentOS operating system running with systemd uses hostname command to manage computer hostname.
Using following command you can change the hostname of linux system, For example you need to set computer hostname to workstation.
# hostnamectl set-hostname workstation
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, run the below command to find the current hostname of your system.
# hostnamectl Static hostname: workstation 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 can also change your system hostname manually by editing configuration file directory. Edit the /etc/hostname file write your system hostname there as show below.
# vim /etc/hostname workstation
Save and close file. After editing the file, you can also set the hostname for the current session to avoid system reboot.
# hostname workstation
Now edit /etc/hosts file to bind new hostname with localhost IP address.
To print the hostname of the system :
# hostname output: # hostname testserver.looklinux.com
To print IP address of the computer :
# hostname -i output: 192.168.0.5
To print the domain name :
# hostname -d output: looklinux.com
To print short hostname :
# hostname -s output: looklinux