How to change hostname in Fedora Linux permanently

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.
Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Fedora Linux
Est. reading time 3 minutes

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

This entry is 11 of 19 in the Linux/Unix Set hostname Tutorial series. Keep reading the rest of the series:
  1. Ubuntu Linux Change Hostname (computer name)
  2. Debian Linux: Change Hostname / Computer Name Permanently
  3. Linux change my hostname / computer system name
  4. Linux Change Hostname
  5. RHEL / Centos Linux 7: Change and Set Hostname Command
  6. OpenBSD Change Hostname
  7. CentOS Linux 5/6 Change Hostname Command
  8. Linux setting hostname and domain name of my server
  9. FreeBSD Change Hostname without reboot
  10. SuSe Linux Change Hostname without reboot
  11. How to set the hostname on Fedora Linux
  12. Ubuntu 18.04 LTS change hostname permanently
  13. Ubuntu set hostname permanently (computer name) command
  14. OpenSUSE Linux set hostname permanently (computer name) command
  15. RHEL 8 Linux set hostname permanently (computer name) command
  16. CentOS 8 Linux set hostname permanently (computer name) command
  17. Ubuntu 20.04 LTS set hostname permanently (computer name) command
  18. Set / Change FQDN on Ubuntu 20.04 LTS
  19. Alpine Linux - Setting system hostname

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • tywan mays Apr 19, 2021 @ 20:39

    this was very helpful i used it on all of my commands

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum