How To Change Hostname on Fedora 39
In this tutorial, we will show you how to change the Hostname on Fedora 39. Fedora, like many Linux distributions, recognizes three types of hostnames: static, transient, and pretty. The static hostname, often referred to as the kernel hostname, is the system’s primary hostname stored in the /etc/hostname
file. The transient hostname is a temporary hostname that the system uses when the static hostname is unavailable. Lastly, the pretty hostname is a free-form UTF-8 hostname for presentation to the user. Understanding these types is crucial for effective hostname management.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you the step-by-step change of Hostname on a Fedora 39.
Prerequisites
Before diving into the installation process, let’s ensure that you have everything you need:
- A server running one of the following operating systems: Fedora 39.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- You will need access to the terminal to execute commands. Fedora 39 provides the Terminal application for this purpose. It can be found in your Applications menu.
- A network connection or internet access.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Change Hostname on Fedora 39
Step 1. Checking the Current Hostname
Before changing the hostname, it’s essential to know the current one. You can check this by using the hostnamectl
command in the terminal:
sudo hostnamectl status
This will print out details about the current static, transient, and pretty hostnames. For example:
Static hostname: host1 Icon name: computer-vm Chassis: vm Machine ID: 5003025f93c1c348948aea0ab275717c Boot ID: f583645af20c48dbab8ba31ea99566bb Virtualization: kvm Operating System: Fedora Linux 39 (Workstation Edition) CPE OS Name: cpe:/o:fedoraproject:fedora:39 Kernel: Linux 5.15.16-300.fc39.x86_64 Architecture: x86-64
The static hostname here is host1
. You can also use the hostname
command to print just the static hostname:
hostname
Step 2. Changing the Hostname.
To change the hostname, we’ll use the hostnamectl set-hostname
command. This command is preferred over the hostname
command as it ensures the change is permanent and persists after a system reboot. Here’s how to use it:
sudo hostnamectl set-hostname new_hostname
Replace new_hostname
with your desired hostname. Remember, a good hostname is unique, easy to remember, and typically contains only letters, numbers, and hyphens.
For example, to change the hostname to host2
:
sudo hostnamectl set-hostname host2
Verify the change was applied:
### sudo hostnamectl status Static hostname: host2 Icon name: computer-vm Chassis: vm Machine ID: 5003025f93c1c348948aea0ab275717c Boot ID: f583645af20c48dbab8ba31ea99566bb Virtualization: kvm Operating System: Fedora Linux 39 (Workstation Edition) CPE OS Name: cpe:/o:fedoraproject:fedora:39 Kernel: Linux 5.15.16-300.fc39.x86_64 Architecture: x86-64
After changing the hostname, it’s important to verify the change. You can do this by running the hostname
command:
hostname
This command should return the new hostname. Additionally, you can check the /etc/hostname
file:
cat /etc/hostname
This command will display the content of the /etc/hostname
file, which should be your new hostname.
Congratulations! You have successfully changed the Hostname. Thanks for using this tutorial for changing the Hostname on your Fedora 39 system. For additional or useful information, we recommend you check the official Fedora website.