Brief: This article describes to how to find the current hostname of the system. Also, how can you change the hostname of your Redhat-based systems?

Advertisement

Changing the hostname permanently on Fedora and CentOS is a simple process that requires editing a few system files. In this article, we will show you how to change the hostname permanently on Fedora and CentOS.

Step 1: Check the current hostname

Before changing the hostname, it’s a good idea to check the current hostname of your Fedora or CentOS system. You can do this by opening a terminal window and running the following command:

hostnamectl 

This will display the current hostname, as well as other system information.

Step 2: Set the new hostname

Choose one of the below methods to change the system’s hostname permanently.

Method 1: Using hostnamectl command

To set the new hostname, you can use the `hostnamectl` command on Ubuntu or the hostname command on Debian. For example, to set the new hostname to “newhostname”, you can run the following command:

sudo hostnamectl set-hostname newhostname 

This will change the hostname for the current session as well as update the /etc/hostname file.

Method 2: Editing /etc/hostname file

To make the hostname change permanent, you need to edit the hostname file on your system. This file contains the system’s hostname, and it is read during the boot process. To edit the file, you can use your favorite text editor. For example, to edit the file using nano, you can run the following command:

sudo nano /etc/hostname 

This will open the hostname file in the nano editor. Replace the current hostname with the new hostname and save the file.

Step 3: Edit the hosts file

In addition to editing the hostname file, you also need to edit the hosts file on your system. This file maps IP addresses to hostnames, and it is read during the boot process. To edit the file, you can run the following command:

sudo nano /etc/hosts 

This will open the hosts file in the nano editor. Look for the line that contains the old hostname and replace it with the new hostname.

Save the file and exit the editor.

Conclusion

Changing the hostname permanently on Fedora and CentOS is a simple process that requires editing a few system files and restarting the network. By following the steps in this article, you can ensure that your new hostname survives reboots and is applied consistently across your system.

Share.
Leave A Reply


Exit mobile version