How to Change the Hostname on AlmaLinux 8 and 9

almalinux how to

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:

  1. Open Terminal:
    • Access your server via SSH or open a terminal session.
  2. Check Current Hostname:
    • Run the following command to check the current hostname:hostnamectl
  3. Change Hostname:
    • Use the hostnamectl command to set the new hostname:sudo hostnamectl set-hostname NewHostname
    • Replace NewHostname with your desired hostname.
  4. 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
  5. Restart the Systemd Hostnamed Service:
    • Apply the changes by restarting the systemd-hostnamed service:sudo systemctl restart systemd-hostnamed

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:

  1. Open Terminal:
    • Access your server via SSH or open a terminal session.
  2. Launch NetworkManager TUI:
    • Start the TUI by running:sudo nmtui
  3. Set System Hostname:
    • In the TUI, select Set system hostname and press Enter.
    • Enter the new hostname and press Enter.
  4. Quit TUI:
    • Select Quit and press Enter to exit the TUI.
  5. Restart the Systemd Hostnamed Service:
    • Apply the changes by restarting the systemd-hostnamed service:sudo systemctl restart systemd-hostnamed

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.