Home Fedora How to Set or Change Hostname in Fedora Linux

How to Set or Change Hostname in Fedora Linux

Setting up hostname is an important task when you are installing the operating system. Hostnames are invented to make human life easy. When you have 100’s of machines in your network it is not easy to remember each machine with its IP address but with hostname it becomes easy. Let’s dive in and see how simple it is to configure hostname in Fedora Linux.

Check Hostname in Fedora Linux

There are different ways to check the hostname in Linux. You can use whichever works best for you.

$ hostname
$ hostnamectl
$ uname -n 
$ cat /etc/hostname
Check Fedora Linux Hostname
Check Fedora Linux Hostname

My machine is a newly installed Fedora 33 running on VirtualBox and from the above image, you can see my hostname is set to “localhost.localdomain”.

Set Temporary Hostname in Fedora Linux

You can set up a temporary hostname which will be available until the next reboot. To set up a temporary hostname run the following command. You need the elevated privilege to change the hostname. Either do it as a root user or run with sudo privileges.

$ sudo hostname shelltips
Set Temporary Hostname in Fedora
Set Temporary Hostname in Fedora

Note, the changes will not be effective in your current terminal session. You have to open a new session or run the following command.

$ exec bash

Your temporary hostname assignment will not modify the hostname file.

$ cat /etc/hostname
Fedora Hostname File
Fedora Hostname File

Go ahead and reboot the machine and the changes will be gone.

Set Permanent Hostname in Fedora Linux

To set up a permanent hostname that persists even after reboot you can use the hostnamectl command. This command comes with all the systems running with systemD.

$ which hostnamectl 
$ type -a hostnamectl
Check hostnamectl Command
Check hostnamectl Command

If you are not someone who used the hostnamectl command before a good place to start is running the help command.

$ hostnamectl -h
hostnamectl Command Help
hostnamectl Command Help

To get the current hostname run the following command without any argument.

$ hostnamectl
Check Fedora Hostname
Check Fedora Hostname

From the above image, you can get the hostname of your machine. There are few more options hostnamectl command displays that will be useful.

To change/set a new hostname run the following command.

$ sudo hostnamectl set-hostname ubuntumint.com
$ exec bash
Change Hostname in Fedora
Change Hostname in Fedora

Now check the hostname file, the hostname is updated.

$ cat /etc/hostname
Updated Hostname
Updated Hostname

The next step is to map the hostname with IP address in the /etc/hosts file. Here I am mapping the hostname to the loopback address.

$ sudo nano /etc/hosts

Add the hostname as shown in the file.

127.0.1.1 ubuntumint.com shelltips
Add Hostname to Host File
Add Hostname to Host File

Run a simple ping command to check if the hostname is effective with mapped IP.

$ ping -c 4 ubuntumint.com
Ping Hostname in Linux
Ping Hostname in Linux

That’s it for this article. This is a simple tutorial but a mandatory one for everyone working with Fedora Linux machines.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.