Rocky Linux 8 is a popular operating system choice for many businesses due to its stability and reliability. One important task that you may need to perform is changing the hostname of your Rocky Linux 8 system. The hostname is the unique identifier for your system on a network, and it is essential to have a meaningful and easily recognizable hostname. In this article, we will guide you through the process of changing the hostname in Rocky Linux 8.
Displaying the Current Hostname
Before we dive into changing the hostname, let’s first find out the current hostname of your Rocky Linux 8 system. To do this, open a terminal and run the following command:
hostnamectl
The output will display information about your system, including the current hostname. For example:
[root@server ~]# hostnamectl
Static hostname: localhost.localdomain
Transient hostname: server
Icon name: computer-vm
Chassis: vm
Machine ID: 2836dc6f733240a0a7678564f019735c
Boot ID: 75bca30024ca42059ff73e898416924e
Virtualization: kvm
Operating System: Rocky Linux 8.3
CPE OS Name: cpe:/o:rocky:rocky:8
Kernel: Linux 4.18.0-240.22.1.el8.x86_64
Architecture: x86-64
Take note of the current hostname as we will use it later in the process.
Changing the System Hostname
Once you have identified the current hostname, you can proceed to change it. There are two methods we will explore: using the hostnamectl
command and using the NetworkManager Text User Interface (nmtui).
Method 1: Using the hostnamectl
Command
To change the hostname using the hostnamectl
command, follow these steps:
- Open a terminal and enter the following command, replacing
new_hostname
with your desired hostname:
hostnamectl set-hostname new_hostname
- Optionally, you can also set a pretty hostname for display purposes by using the
--pretty
flag:
hostnamectl set-hostname "new_pretty_hostname" --pretty
- After changing the hostname, you need to update the
/etc/hosts
file. Open the file using your preferred text editor:
nano /etc/hosts
- Add an entry for the new hostname, for example:
127.0.0.1 new_hostname
- Save and exit the file.
- Restart the
systemd-hostnamed
service to apply the changes:
systemctl restart systemd-hostnamed
Method 2: Using the NetworkManager Text User Interface (nmtui)
Alternatively, you can change the hostname using the NetworkManager Text User Interface (nmtui). Follow these steps:
- Open a terminal and enter the following command:
nmtui
- In the nmtui interface, navigate to “Set system hostname” and press Enter.
- Enter your desired hostname and press Enter.
- Exit nmtui.
- Restart the
systemd-hostnamed
service to apply the changes:
systemctl restart systemd-hostnamed
Verifying the Change
To ensure that the hostname has been successfully changed, you can use the hostnamectl
command once again. Open a terminal and enter the following command:
hostnamectl
The output should display the new hostname, both the static and pretty versions, as well as other system information. For example:
[root@server ~]# hostnamectl
Static hostname: new_hostname
Pretty hostname: new_pretty_hostname
Icon name: computer-vm
Chassis: vm
Machine ID: 2836dc6f733240a0a7678564f019735c
Boot ID: 75bca30024ca42059ff73e898416924e
Virtualization: kvm
Operating System: Rocky Linux 8.3
CPE OS Name: cpe:/o:rocky:rocky:8
Kernel: Linux 4.18.0-240.22.1.el8.x86_64
Architecture: x86-64
Congratulations! You have successfully changed the hostname of your Rocky Linux 8 system.
Conclusion
Changing the hostname in Rocky Linux 8 is a straightforward process that can be done using either the hostnamectl
command or the NetworkManager Text User Interface (nmtui). By following the steps outlined in this guide, you can easily set a new hostname for your system. Remember, having a meaningful and recognizable hostname is essential for managing your system efficiently.
If you are looking for reliable and scalable cloud hosting solutions, Shape.host is here to help. With our Cloud VPS services, you can enjoy the benefits of high-performance virtual servers backed by top-notch support. Visit our website at Shape.host to learn more about our services and how we can empower your business with efficient, secure, and scalable cloud hosting solutions.