How to change hostname in Fedora Linux permanently

last updated in Categories ,

How do I change the hostname of a Fedora Linux system permanently using the command line tools from localhost to fedora28-nixcraft? How do I change hostname in Fedora Linux permanently from localhost.localdomain to fedora28-nixcraft?

You can use the hostnamectl command to display or set the Fedora Linux system’s host name. In this tutorial, you will learn how to change your hostname on Fedora Linux using various methods.

What is hostname?

A hostname is nothing but your computer or server name. One can use the hostname to identify and define itself on a network. For example, hostname www13 indicates a web server. Sometimes you setup hostname as a fully qualified domain name (FQDN) such as or simply

Rules for naming hostname on the Fedora Linux

Rules are pretty simple. A hostname on Fedora Linux may only contain letters a-z, numerals 0-9, and dashes (-). An example is www-13. The FQDN for that server might be

How To change hostname in Fedora Linux server

Steps to change your hostname on Fedora Linux:

  1. Login to your server: ssh user@server-name
  2. Become a root user: sudo -s or su -
  3. Run command: hostnamectl set-hostname new-name

Let us see steps in details to change a system’s hostname i.e. rename a computer/server name when using a Fedora Linux based system.

Find your current computer name

Type the following hostname command or hostnamectl command:
$ hostname
Sample outputs:


$ hostnamectl
Sample outputs:

   Static hostname: localhost.localdomain
         Icon name: computer-vm
           Chassis: vm
        Machine ID: c86ab4f4c14c435baff0597747b349d9
           Boot ID: 2145ab2be9de49b6bca1837bb8d5a2f8
    Virtualization: kvm
  Operating System: Fedora 28 (Server Edition)
       CPE OS Name: cpe:/o:fedoraproject:fedora:28
            Kernel: Linux 4.16.3-301.fc28.x86_64

Fedora change hostname

Let us change hostname in Fedora Linux. For example, change hostname to fedora28-nixcraft, enter:
$ sudo hostname fedora28-nixcraft
$ hostname

Sample outputs:


As compared to hostnamectl command, hostname command just read or set the hostname for the current session. It only exists for compatibility reasons. Hence, I recommend using the hostnamectl command as discussed below.

How do I change Hostname Permanently on the Fedora Linux?

Edit the file /etc/hostname, enter:
$ sudo vi /etc/hostname
Delete the existing name and replace it with a new name:


Save and close the file. You may also need to edit the /etc/hosts file, enter:
$ sudo vi /etc/hosts
Find all references to server1 and replace with server2:   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6	fedora28-nixcraft

Save and close the file. Please note that the host name is usually set once at system startup. This is an older method but still works on all versions of Fedora Linux.

How to set the hostname on Fedora Linux

With the latest version of Fedora Linux that uses systemd, it is possible to use a single command as follows:
# hostnamectl set-hostname {NameHere}
# hostnamectl set-hostname fedora28-nixcraft

Sample outputs:
Command to change hostname in Fedora Linux permanently

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Join the discussion at