How to Change Hostname on AlmaLinux

Seamlessly change your AlmaLinux system's hostname with this guide. Explore temporary and permanent methods using commands, config files, and utilities.

How to Change Hostname on AlmaLinux

Introduction

The hostname is a unique identifier assigned to every computer or device connected to a network. It facilitates seamless communication between systems within the same network. There may arise situations where you need to modify the hostname of your AlmaLinux machine, such as when setting up a server or to better align it with the system's purpose. This comprehensive guide will walk you through the process of changing the hostname on your AlmaLinux system.


Prerequisites

Before proceeding, ensure that you have administrative privileges or are logged in as the root user. Modifying the hostname requires elevated access.


Temporarily Changing the Hostname

If you need to change the hostname temporarily, you can utilize the hostname command without altering any configuration files. However, this change will only persist until the next system restart.

  1. Launch the terminal emulator.
  2. Verify the current hostname by executing:
hostname
  1. To temporarily change the hostname, run the following command, replacing new-hostname with your desired hostname:
sudo hostname new-hostname

Permanently Changing the Hostname

To make a permanent change to the hostname, you need to modify the appropriate configuration files. Follow these steps:

  1. Launch the terminal emulator.
  2. Edit the /etc/hostname file using a text editor like nano:
sudo nano /etc/hostname
  1. Within the text editor, replace the existing hostname with your desired new hostname.
  2. Save the file and exit the text editor.
  3. Next, edit the /etc/hosts file:
sudo nano /etc/hosts
  1. In this file, locate the line starting with your system's IP address (e.g., 127.0.1.1 or 127.0.0.1) and modify the existing hostname to the new one.
  2. Save the file and exit the text editor.
  3. After updating the configuration files, reboot your system for the changes to take effect:
sudo reboot
  1. Once the system restarts, verify the new hostname by executing:
hostname

The new hostname should be displayed in the terminal.


Changing the Hostname Using the Hostnamectl Utility

AlmaLinux provides the hostnamectl utility, which simplifies the process of changing the hostname. This tool allows you to modify both the static and transient hostname settings.

  1. Launch the terminal emulator.
  2. To change the static hostname, execute the following command, replacing new-hostname with your desired hostname:
sudo hostnamectl set-hostname new-hostname
  1. If you want to change the transient (temporary) hostname, run the following command:
sudo hostnamectl set-hostname --pretty new-hostname

The --pretty option sets the pretty hostname, which is used for display purposes.

  1. Reboot your system for the changes to take effect:
sudo reboot
  1. After the system restarts, verify the new hostname by running:
hostnamectl

This command will display the current static and transient hostname settings.


Conclusion

Changing the hostname on your AlmaLinux system is a straightforward process that can be accomplished using the hostname command for temporary changes or by modifying the /etc/hostname and /etc/hosts files for permanent changes. Additionally, the hostnamectl utility provides a convenient way to manage both static and transient hostname settings.

Remember to update any relevant configuration files or services that rely on the hostname after making the change. A consistent and meaningful hostname can greatly enhance the manageability and organization of your AlmaLinux system.


Enjoying our content? Your support keeps us going! 🚀

Consider buying us a coffee to help fuel our creativity.