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:

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

127.0.1.1  workstation

More Example

Example-1:

To print the hostname of the system :

# hostname
output:
# hostname
testserver.looklinux.com

Example-2:

To print IP address of the computer :

# hostname -i
output:
192.168.0.5

Example-3:

To print the domain name :

# hostname -d
output:
looklinux.com

Example-4:

To print short hostname :

# hostname -s
output:
looklinux
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 www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

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