In the world of server administration, knowing how to change the hostname of your system is a fundamental skill. Whether you’re setting up a new server or rebranding an existing one, the hostname plays a crucial role in identifying and accessing your server. In this article, we will walk you through the step-by-step process of changing the hostname in AlmaLinux 9, a popular Linux distribution known for its stability and performance.
Checking the Current Hostname
Before we dive into changing the hostname, let’s first check the current hostname of your system. Open a terminal and enter the following command:
hostnamectl
The output will display various details about your system, including the current hostname. Take note of this information as it will be useful later in the process.
Changing the Hostname
Now that you know the current hostname, it’s time to change it to your desired name. AlmaLinux provides a simple command to change the hostname:
hostnamectl set-hostname your-desired-hostname
Replace your-desired-hostname
with the new hostname you wish to assign to your system. For example, if you want to set the hostname to “examplecloud.nethostname,” the command would be:
hostnamectl set-hostname examplecloud.nethostname
Optionally, you can also set a pretty hostname, which is a more user-friendly version of the hostname. To set the pretty hostname, use the following command:
hostnamectl set-hostname "examplecloud production server" --pretty
This command sets the pretty hostname to “examplecloud production server.” Feel free to customize it according to your preferences and requirements.
Updating the Hosts File
To ensure that the new hostname is properly mapped to the IP address of your system, you need to update the /etc/hosts
file. Open the file using your favorite text editor:
nano /etc/hosts
Within the file, you will find an entry similar to 127.0.0.1 localhost
or 127.0.0.1 your-current-hostname
. Add a new line below this entry and insert the following:
127.0.0.1 your-new-hostname
For example, if your new hostname is “examplecloud.net,” the line would look like this:
127.0.0.1 examplecloud.net
Save the changes and exit the editor.
Restarting the systemd-hostnamed Service
To apply the changes and ensure that the new hostname is activated, you need to restart the systemd-hostnamed
service. Use the following command to accomplish this:
systemctl restart systemd-hostnamed
With the service restarted, the new hostname will take effect immediately.
Alternative Method: Using NetworkManager’s Text User Interface
If you prefer a graphical interface, AlmaLinux offers an alternative method to set or change the hostname using NetworkManager’s Text User Interface (nmtui). Follow these steps:
- Open a terminal and run the command
nmtui
to launch the interface. - Select “Set system hostname” and press Enter.
- Enter the new hostname in the provided field and press Enter.
- Restart the
systemd-hostnamed
service to apply the changes:
systemctl restart systemd-hostnamed
Verifying the Hostname Change
To ensure that the hostname has been successfully changed, you can use the hostnamectl
command again. Open a terminal and enter:
hostnamectl
The output will display the new hostname under the “Static hostname” and “Pretty hostname” fields, confirming that the change has been applied.
Conclusion
Changing the hostname in AlmaLinux 9 is a straightforward process that can be done using either the command line or a graphical interface. By following the steps outlined in this guide, you can easily customize the hostname to suit your needs. Remember to update the /etc/hosts
file and restart the systemd-hostnamed
service to ensure a smooth transition.
At Shape.host, we specialize in providing reliable and scalable cloud hosting solutions. If you’re looking for high-performance Linux SSD VPS hosting, be sure to check out our services at Shape.host. Our team of experts is ready to assist you in optimizing your server setup for maximum efficiency and security.