How to Change Hostname in AlmaLinux 8 (Step-by-Step)

Change hostname in AlmaLinux 8 with hostnamectl, fix local name resolution, keep cloud-init from overwriting it, and verify the result safely in minutes.
A midnight-blue server with a glowing network node and an illuminated hostname badge without readable text.

Change hostname in AlmaLinux 8 with hostnamectl, a matching local hosts entry, and a few checks that catch incomplete changes. The update usually takes less than five minutes and does not require a reboot.

Prerequisites

  • An AlmaLinux 8 VPS with root access or a user who can run commands with sudo.
  • An SSH session to the server and a text editor such as nano.
  • A new short hostname such as web01, or an FQDN such as web01.example.com; use lowercase letters, digits, hyphens, and dots only.
  • The server’s primary IP address if you want the new FQDN to resolve locally, plus access to your domain’s DNS records if other machines must resolve it.
  • A VPSLake Linux VPS with AlmaLinux 8 if you need a fresh server for this procedure.

Step 1: Inspect the current name

Check each hostname type before changing anything so you can tell whether an old value is coming from the static configuration, the current kernel state, or a descriptive label.

cat /etc/almalinux-release
hostnamectl status --static
hostnamectl status --pretty
hostnamectl status --transient
nmcli general hostname

The release line should identify AlmaLinux 8. The static or transient checks may be empty on a minimally configured VPS, which is not an error. A populated result might look like this:

AlmaLinux release 8.x
old-web.example.com

old-web.example.com

The static hostname is the value you normally want to set permanently. The pretty hostname is optional and is meant for a human-readable description, not for DNS or service identity.

Step 2: Set the static hostname

Use hostnamectl instead of editing /etc/hostname by hand; it updates the systemd hostname service, the running system, and the persistent file together.

sudo hostnamectl set-hostname NEW_HOSTNAME

Replace NEW_HOSTNAME with a value such as web01 or web01.example.com. An FQDN is useful when the VPS has a public domain, but setting it here does not create a DNS record.

AlmaLinux 8 also supports an optional pretty hostname for a label that may contain spaces:

sudo hostnamectl set-hostname "NEW_PRETTY_NAME" --pretty

Replace NEW_PRETTY_NAME with something like Web server in Miami. The commands normally return no text. Confirm both values immediately:

hostnamectl status --static
hostnamectl status --pretty
cat /etc/hostname

Expected output is similar to:

web01.example.com
Web server in Miami
web01.example.com

The RHEL 8 hostname documentation describes the static hostname as the value stored in /etc/hostname; hostnamectl also activates the new value through systemd-hostnamed.

Step 3: Make the name resolve locally

The hostname can be set correctly and still fail lookups if the VPS has no DNS record yet, so add a local mapping for services that need to resolve the server’s own name.

Find the source address used for the default IPv4 route:

ip -4 route get 1.1.1.1

Look for the src value, then open the hosts file:

sudo nano /etc/hosts

Keep the existing localhost and IPv6 lines. Add a line in this format, replacing every uppercase placeholder:

SERVER_IP NEW_HOSTNAME NEW_SHORT_NAME

For example, an FQDN might use this entry:

203.0.113.40 web01.example.com web01

If you chose only web01, use SERVER_IP web01 instead. Save the file, then test the local resolver:

getent hosts NEW_HOSTNAME
hostname --fqdn

Successful output contains the server address and the chosen name:

203.0.113.40  web01.example.com web01
web01.example.com

The hosts file affects this server only. To make the name work from laptops, monitoring systems, or other VPSs, create an A record for IPv4 or an AAAA record for IPv6 at your DNS provider.

Step 4: Change it with NetworkManager when needed

nmcli is a useful alternative on AlmaLinux 8 because NetworkManager owns the system hostname on many installations and exposes a direct hostname setting.

Display the current NetworkManager value and set the new one:

nmcli general hostname
sudo nmcli general hostname NEW_HOSTNAME
nmcli general hostname

The final command should print the new value:

web01.example.com

You can also use the text interface if you prefer a menu over a command:

sudo dnf install -y NetworkManager-tui
sudo nmtui

In the menu, choose Set system hostname, enter the new name, select OK, and choose Quit. This changes the same static hostname managed by hostnamectl; it does not edit /etc/hosts or publish DNS, so complete Step 3 when local resolution is required.

Step 5: Refresh shells and dependent services

The kernel sees the new name immediately, but an existing SSH prompt and applications that read the hostname only at startup can retain the old value.

Check that the hostname service is active and that the persistent file is correct:

systemctl is-active systemd-hostnamed
cat /etc/hostname

Expected output:

active
web01.example.com

Reconnect over SSH to refresh your shell prompt. Restart only a service that is known to cache the hostname, using its real unit name:

sudo systemctl restart YOUR_SERVICE

Replace YOUR_SERVICE with an actual application service. Do not restart NetworkManager solely because the hostname changed, and do not reboot unless another maintenance task requires it.

Verify the new hostname

Run these checks together to confirm the persistent name, optional description, fully qualified result, and resolver mapping:

hostnamectl status --static
hostnamectl status --pretty
hostname --fqdn
getent hosts NEW_HOSTNAME

The static hostname and FQDN should show the new name. The pretty check is blank unless you set one, and getent should return the address from /etc/hosts or DNS. If the first and third checks agree and the resolver returns the expected address, the AlmaLinux 8 configuration is complete.

Troubleshooting

The old hostname returns after a reboot

Cloud-init, DHCP, or the VPS image’s provisioning settings may be applying a hostname during boot. Check whether cloud-init is installed and reporting a running configuration:

rpm -q cloud-init
sudo cloud-init status --long

If the package is installed and the provider permits local overrides, preserve the manual value for future boots:

sudo install -d -m 0755 /etc/cloud/cloud.cfg.d
printf 'preserve_hostname: true\n' | sudo tee /etc/cloud/cloud.cfg.d/99-preserve-hostname.cfg
sudo hostnamectl set-hostname NEW_HOSTNAME

If the provider’s provisioning system still resets it, update the hostname in the VPS provisioning or control-panel settings too.

hostnamectl: invalid hostname

The value contains a space, underscore, or unsupported punctuation, or an FQDN label starts or ends with a hyphen. Use lowercase letters, digits, hyphens, and dots for the static name; put spaces in the optional --pretty value instead.

hostname --fqdn prints localhost or fails

The static hostname exists, but local name resolution does not map it to an address. Add the server’s real IP, FQDN, and short alias to /etc/hosts, then rerun getent hosts NEW_HOSTNAME. If other machines need the name, add the corresponding public DNS record as well.

nmtui: command not found

The text interface is an optional package on minimal AlmaLinux 8 images. Install NetworkManager-tui with dnf, or skip the menu and use hostnamectl, which is the simpler method for a remote SSH session.

Next steps

  • Create and test the public A or AAAA record if the hostname is an FQDN.
  • Configure a matching reverse-DNS/PTR record in the VPS control panel when mail or monitoring depends on reverse lookups.
  • Update backup, monitoring, and configuration-management inventory if those systems identify the server by its old hostname.

FAQ

Does changing the hostname require a reboot on AlmaLinux 8?

No. hostnamectl changes the active hostname and writes the persistent value immediately. Reconnect your SSH session and restart only applications that read the hostname once during startup.

Should I choose a short hostname or an FQDN?

A short name is enough for a private, single-server setup. Choose an FQDN when the VPS participates in DNS, TLS, mail, monitoring, or a larger cluster, and make sure that name resolves locally and publicly where needed.

Will this change update DNS or reverse DNS?

No. The command changes the operating system’s local identity. Manage the forward record with your DNS provider and the PTR record through the system that controls your VPS address.

Why is the pretty hostname different from the static hostname?

The static hostname is the machine name used by the operating system and commonly stored in /etc/hostname. The pretty hostname is an optional descriptive label for people, so it may contain spaces and is not a substitute for a DNS name.

Samrat Ghosh
Written by

Samrat Ghosh

Founder & Infrastructure Engineer

Samrat Ghosh is the founder of VPSLake, where he builds and runs the remote desktop and VPS hosting infrastructure the company is built on. He writes hands-on guides about RDP, Windows Server, VPS management and secure remote access - the practical documentation he wishes had…

Previous Article

How to Buy Windows RDP: Order to Login

Next Article

Best RDP Provider in USA (2026): Private, Admin Picks

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨