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
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
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
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
If you are not someone who used the hostnamectl command before a good place to start is running the help command.
$ hostnamectl -h
To get the current hostname run the following command without any argument.
$ hostnamectl
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
Now check the hostname file, the hostname is updated.
$ cat /etc/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
Run a simple ping command to check if the hostname is effective with mapped IP.
$ ping -c 4 ubuntumint.com
That’s it for this article. This is a simple tutorial but a mandatory one for everyone working with Fedora Linux machines.