How to change a hostname on Redhat 7 Linux

The hostname of your Red Hat Enterprise Linux system is important because it’s used to identify the device on a network. The hostname is also shown in other prominent places, such as in the terminal prompt. If you have not bothered to change the hostname yet, your system probably bears the default localhost.localdomain name, which is not very helpful.

In this tutorial, we will cover the step by step instructions to change the hostname on an RHEL 7 Linux system. If you can’t easily identify your system’s purpose from the hostname, it’s time to change it. Let’s get started.

In this tutorial you will learn:

  • How to change system hostname on Red Hat 7 Linux
  • How to view the currently configured hostname
Changing the system hostname on Red Hat 7 Linux
Changing the system hostname on Red Hat 7 Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Red Hat 7 Linux
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Change hostname on Red Hat 7 Linux step by step instructions



  1. To change the system’s hostname, we will need to edit the /etc/hostname file. Open this file with nano or your preferred text editor, and with root permissions. In this example, we will change our hostname to rhel7.
    # nano /etc/hostname
    
    Place your desired RHEL 7 hostname in this file
    Place your desired RHEL 7 hostname in this file
  2. After you have made your changes to this file, save and exit it. Then, execute the following command (once again with root permissions) to make the changes take effect system wide:
    # systemctl restart systemd-hostnamed
    
  3. You may notice that your terminal still reflects the old hostname, even after executing the above command. Keep in mind that you will need to reopen terminals or log out and log back in in order to notice the new hostname replacing the old one everywhere. You can verify your new hostname with either of the following commands:
    $ hostname
    or
    $ hostnamectl
    

Closing Thoughts




In this tutorial, we saw how to change the hostname on a Red Hat Enterprise Linux 7 system. We also learned about the importance of picking an applicable hostname to assist in the easy identification of a system. Administrators can use this method to ensure that they have a network of appropriately named devices.