Linux Administrator

How to Change Hostname on Fedora and CentOS

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.

Change Hostname

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: workstation

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

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.  workstation

More Example


To print the hostname of the system :

# hostname
# hostname


To print IP address of the computer :

# hostname -i


To print the domain name :

# hostname -d


To print short hostname :

# hostname -s
Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment