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
|Category||Requirements, Conventions or Software Version Used|
|System||Red Hat 7 Linux|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Change hostname on Red Hat 7 Linux step by step instructions
- To change the system’s hostname, we will need to edit the
/etc/hostnamefile. Open this file with nano or your preferred text editor, and with root permissions. In this example, we will change our hostname to
# nano /etc/hostname
- 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
- 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
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.