
Changing the hostname of an AlmaLinux system is a straightforward process that can be done using either the command line or a text user interface (TUI). This guide will walk you through both methods for AlmaLinux 8 and 9.
Prerequisites
- Administrative privileges on the server.
- Access to the server either physically or via SSH.
Method 1: Using the Command Line
Steps:
- Open Terminal:
- Access your server via SSH or open a terminal session.
- Check Current Hostname:
- Run the following command to check the current hostname:
hostnamectl
- Run the following command to check the current hostname:
- Change Hostname:
- Use the
hostnamectl
command to set the new hostname:sudo hostnamectl set-hostname NewHostname
- Replace
NewHostname
with your desired hostname.
- Use the
- Update /etc/hosts File:
- Open the
/etc/hosts
file in a text editor:sudo nano /etc/hosts
- Update the line that contains your old hostname to reflect the new hostname. For example:
127.0.0.1 localhost 127.0.1.1 NewHostname
- Open the
- Restart the Systemd Hostnamed Service:
- Apply the changes by restarting the
systemd-hostnamed
service:sudo systemctl restart systemd-hostnamed
- Apply the changes by restarting the
Verification:
- Run the
hostnamectl
command again to verify that the hostname has been updated:hostnamectl
Method 2: Using NetworkManager’s Text User Interface (TUI)
Steps:
- Open Terminal:
- Access your server via SSH or open a terminal session.
- Launch NetworkManager TUI:
- Start the TUI by running:
sudo nmtui
- Start the TUI by running:
- Set System Hostname:
- In the TUI, select Set system hostname and press Enter.
- Enter the new hostname and press Enter.
- Quit TUI:
- Select Quit and press Enter to exit the TUI.
- Restart the Systemd Hostnamed Service:
- Apply the changes by restarting the
systemd-hostnamed
service:sudo systemctl restart systemd-hostnamed
- Apply the changes by restarting the
Verification:
- Run the
hostnamectl
command to verify the hostname change:hostnamectl
Additional Tips
- Ensure that the new hostname complies with your organization’s naming conventions.
- If the server is part of a domain, you may need to update the DNS records to reflect the new hostname.
- Always perform these changes during a maintenance window to avoid disrupting services.