Learn how to easily change hostname in Linux, including Red Hat Enterprise Linux and Fedora. This step-by-step guide will help system administrators understand the importance of hostnames, how to configure them, and avoid common networking issues. Whether you’re managing local or remote systems, this guide will ensure you can efficiently update your system’s hostname.
Understanding and Changing Hostnames in Linux
Every computer has a unique identity, defined by its hostname and IP address. While IP addresses are essential for networking, it’s not practical to refer to systems by their IP addresses. Instead, we use hostnames, which are human-friendly names for machines. By mapping a hostname to an IP address, connecting to a system becomes much easier.
Why Hostnames Matter
Hostnames are crucial for system administrators. They allow us to identify and organize systems in a way that’s easy to understand. This is especially important when managing systems remotely. For instance, I’ve seen situations where companies change hostnames or IPs of storage servers, only to realize later that it caused issues with data replication.
In this article, I’ll focus on how to change hostname in Linux (Redhat) and Fedora.
Step 1: View Current Hostname
Open the terminal > Run the following command:hostname
This will display the current hostname of your system. For example, it might show something like localhost
. Alternatively, use the hostnamectl
command for more detailed information: This will display the Current hostname, System architecture, Kernel version, Other system-related details
Step 2: Change the Hostname
- Use the following command to change your hostname:
sudo hostnamectl set-hostname 'Coderepublics'
Replace Coderepublics
with the hostname you want to set. Enter your root user credentials when prompted.
Verify the change by running: hostnamectl
If the new hostname doesn’t reflect immediately, restart your machine to apply the changes. After that you’ll see on the below image that the hostname is changed from localhost to Coderepublics.
Also Read: How to install Red Hat Enterprise Linux
Step 3: Update the Loopback Address
Open the /etc/hosts
file using a text editor (e.g., nano
): Run command sudo nano /etc/hosts
Step 4: Verify the Configuration
Use the ping
command to test your hostname: ping Coderepublics. If configured correctly, the system will resolve your hostname to the loopback IP address.