Change hostname on AlmaLinux

The hostname of a Linux system is important because it’s used to identify the device on a network. The hostname is also shown in other prominent places, such as in the terminal prompt. This gives you a constant reminder of which system you’re working with. It’s a real life saver when you’re managing multiple systems through SSH and those command line terminals start to blend together in your mind.

Of course, IP addresses are used when devices need to communicate with each other, but those can change frequently. Hostnames give us a way to know which device we’re interacting with either on the network or physically, without remembering a bunch of numbers that are subject to change. Thus, it’s important that your system bears a hostname which helps you to identify it quickly. For example, “backup-server” is much more informative than “server2.” If you can’t easily identify a system’s purpose from the hostname, it’s time to change it.

In this guide, we’ll show you how to change the hostname on AlmaLinux. This can be especially useful if you’ve recently migrated from CentOS to AlmaLinux and need to update the hostname accordingly. Changing the hostname can be done either by command line or GUI, and we’ll show you the steps for both methods below.

In this tutorial you will learn:

  • How to change the AlmaLinux hostname from command line
  • How to change the AlmaLinux hostname from GNOME GUI
Changing the hostname in AlmaLinux

Changing the hostname in AlmaLinux

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System AlmaLinux
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

Change AlmaLinux hostname from command line

Use the following steps to change AlmaLinux’s hostname using systemd’s hostnamectl command.

  1. First, let’s check the current hostname by using either the hostname or hostnamectl command.
    $ hostname
    localhost.localdomain
    
    $ hostnamectl
       Static hostname: localhost.localdomain
             Icon name: computer-vm
               Chassis: vm
            Machine ID: abeb8e24781744f789b0fcaad0bb3c40
               Boot ID: 1de10801654840ada962499ce99483d6
        Virtualization: vmware
      Operating System: AlmaLinux 8.3 (Purple Manul)
           CPE OS Name: cpe:/o:almalinux:almalinux:8.3
                Kernel: Linux 4.18.0-240.el8.x86_64
    

    Both commands indicate that our hostname is localhost.localdomain, the default hostname for new AlmaLinux installations.

  2. Next, change the hostname with the following command. In this example, we’ll change our hostname to linuxconfig.
    $ hostnamectl set-hostname linuxconfig
    

    Run the commands from Step 1 again to confirm the new change.

  3. Lastly, edit the /etc/hosts file to reflect the change. For example:

    Add the following two lines to your file, replacing this example with your desired hostname. You can leave the existing, default lines in the file as well.

    127.0.0.1	linuxconfig
    ::1			linuxconfig
    
Editing the hosts file

Editing the hosts file

That’s all there is to it. Note that your currently opened terminals will not yet reflect the change, but newly opened terminals will.

Change hostname from GNOME GUI

If you have GNOME GUI installed on AlmaLinux, you can use the following steps to change the system’s hostname.

  1. AlmaLinux doesn’t let a normal user edit the hostname from GUI, so we’ll need to open the GNOME settings menu with our root account. To do this, run the following command as root.
    # gnome-control-center
    
  2. Click on the Details tab at the bottom and then click on About.
  3. In this menu, you can click the area titled ‘Device Name’ and enter your desired hostname. Just press enter once you’re done with the change, and then you can close this window.
  4. Change the hostname via GUI

    Change the hostname via GUI

  5. Afterwards, type hostnamectl into the terminal you have opened so you can verify that the change was made.
    $ hostnamectl
       Static hostname: linuxconfig
             Icon name: computer-vm
               Chassis: vm
            Machine ID: abeb8e24781744f789b0fcaad0bb3c40
               Boot ID: 1de10801654840ada962499ce99483d6
        Virtualization: vmware
      Operating System: AlmaLinux 8.3 (Purple Manul)
           CPE OS Name: cpe:/o:almalinux:almalinux:8.3
                Kernel: Linux 4.18.0-240.el8.x86_64
    

Closing Thoughts

In this guide, we saw a command line and GUI method for changing the system hostname in AlmaLinux. We also learned about the importance of picking an applicable hostname to assist in the easy identification of a system. Administrators can use these methods to ensure that their AlmaLinux computers have appropriate and easily identifiable hostnames.