How to Change Hostname in AlmaLinux 9

Change hostname in AlmaLinux 9 with hostnamectl, local name resolution, NetworkManager checks, and fixes for reboot or DNS issues on a VPS without a reboot.
A midnight-blue AlmaLinux server with a glowing network node and a blue hostname connection line.

Change hostname in AlmaLinux 9 with hostnamectl, then make the name resolve locally so services do not fall back to an old value. The complete setup usually takes less than five minutes and does not require a reboot.

Prerequisites

  • AlmaLinux 9 on the VPS, with root access or a normal account that can use sudo.
  • An active SSH connection and an editor such as nano or vi.
  • A new short hostname such as app01, or an FQDN such as app01.example.com; use lowercase letters, digits, hyphens, and dots for the static name.
  • The VPS’s primary IP address and access to your DNS provider if the new name must resolve outside this server.
  • A VPSLake Linux VPS running AlmaLinux 9 if you need a fresh server for this change. Changing a hostname does not need extra RAM or disk space.

Step 1: Inspect the current hostname

Check the release and each hostname type first, because a VPS can have a persistent name while its current shell or network configuration still shows another value.

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

The release should identify AlmaLinux 9. Empty static or pretty values are normal on a newly provisioned server; a transient value may have come from DHCP or the image configuration.

AlmaLinux release 9.x
old-app.example.com
old-app.example.com

The static hostname is the operating system’s durable name. Use a pretty hostname only as an optional human-readable label; it is not a DNS name.

Step 2: Set the AlmaLinux 9 hostname

hostnamectl updates the systemd hostname service and /etc/hostname through the supported interface, so you do not need to edit that file manually.

sudo hostnamectl set-hostname NEW_HOSTNAME

Replace NEW_HOSTNAME with app01 or app01.example.com. The command normally prints nothing. Confirm the new static value and the file that stores it:

hostnamectl status --static
cat /etc/hostname

Expected output:

app01.example.com
app01.example.com

If you want a descriptive label as well, set it separately. Spaces are valid in a pretty hostname but not in the static hostname:

sudo hostnamectl set-hostname "NEW_PRETTY_NAME" --pretty
hostnamectl status --pretty

For example, NEW_PRETTY_NAME could be Production application server. AlmaLinux 9 activates the change through systemd-hostnamed; manually restarting that service is normally unnecessary. The RHEL 9 hostname documentation describes the same hostname types and commands used by AlmaLinux 9.

Step 3: Add local name resolution

The hostname can be correct while lookups still return nothing, so add a local /etc/hosts record when the server or its services must resolve the name before DNS is available.

Identify the address used for the default IPv4 route:

ip -4 route get 1.1.1.1

Use the address after src as SERVER_IP. Open the hosts file and keep its existing localhost and IPv6 entries:

sudo nano /etc/hosts

For an FQDN, add a line like this, replacing every uppercase placeholder:

SERVER_IP NEW_HOSTNAME NEW_SHORT_NAME

For example:

203.0.113.40 app01.example.com app01

If you chose only app01, use SERVER_IP app01 instead. Save the file, then test the system resolver and the fully qualified result:

getent hosts NEW_HOSTNAME
hostname --fqdn

Successful output resembles:

203.0.113.40  app01.example.com app01
app01.example.com

This edit affects the current VPS only. Create an A record for IPv4 or an AAAA record for IPv6 at your DNS provider if other computers must resolve the name.

Step 4: Use NetworkManager instead

AlmaLinux 9 uses NetworkManager, so nmcli is a useful alternative when hostname settings are managed as part of the network configuration. Use this method instead of Step 2, not in addition to it.

Display and set the NetworkManager hostname:

nmcli general hostname
sudo nmcli general hostname NEW_HOSTNAME
nmcli general hostname

The final command should print the new name:

app01.example.com

For a menu-driven terminal interface, install the optional package and launch it:

sudo dnf install -y NetworkManager-tui
sudo nmtui

Choose Set system hostname, enter the static hostname, select OK, and then choose Quit. nmtui changes the system hostname but does not create DNS records or edit /etc/hosts, so complete Step 3 when local resolution is required.

Step 5: Refresh the session and affected services

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

Check the hostname service and persistent file:

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

Expected output:

active
app01.example.com

Reconnect over SSH to refresh the shell prompt. Restart an application only if it caches the hostname at startup, using its actual unit name:

sudo systemctl restart YOUR_SERVICE

Replace YOUR_SERVICE with a real service such as an application you administer. Do not restart NetworkManager merely because the hostname changed, and do not reboot unless another maintenance task requires it.

Verify the new hostname

Run these checks as a final pass. They confirm the persistent name, optional label, local FQDN result, and resolver mapping:

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

The static hostname and hostname --fqdn result should match your chosen name. The pretty value is blank unless you set one, and getent should return the expected server address. If DNS is already configured, the final result can come from DNS instead of /etc/hosts.

Troubleshooting

The SSH prompt still shows the old name

The prompt was created when the shell started and may not rebuild itself after the hostname changes. Open a new SSH session; the new prompt should appear without changing the hostname again. Services can have the same behavior, so restart only the affected service.

hostname --fqdn returns the old name

The static setting is new, but /etc/hosts or DNS still gives the old answer. Search the local file for stale entries, remove or update the old hostname mapping, then rerun getent hosts NEW_HOSTNAME:

grep -nE 'OLD_HOSTNAME|NEW_HOSTNAME' /etc/hosts
getent hosts NEW_HOSTNAME

If the local file is correct but another machine sees the old value, update the public A or AAAA record and allow for DNS caching.

The hostname changes back after a reboot

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

rpm -q cloud-init

If it is installed and you want to preserve the manual hostname, create a cloud-init override and set the name again:

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 process still replaces it, update the hostname in the VPS provisioning or control-panel settings too.

nmtui: command not found

The text interface is optional on minimal AlmaLinux 9 installations. Install NetworkManager-tui with dnf, or skip the menu and use hostnamectl, which is the simpler choice for a remote SSH session.

FAQ

Can I use a short hostname without owning a domain?

Yes. A name such as app01 is valid for a private server or a small environment. Use an FQDN when TLS, mail, monitoring, or multi-server tooling expects a globally unique DNS name.

Does changing the hostname rename my VPS in the control panel?

No. hostnamectl changes the AlmaLinux operating system’s identity. A client area or VPS control panel label, reverse-DNS value, and public DNS record are separate settings that must be changed in their respective systems.

Should I edit /etc/hostname directly?

Usually not. hostnamectl writes the persistent file and activates the running hostname together, reducing the chance that the file and the current system state disagree.

Will changing the hostname interrupt my SSH connection?

Normally, no. The current connection stays open, although its prompt may retain the old name until you reconnect. Restart only services that cache the hostname, and schedule a reboot only if another change requires one.

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

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

Next Article

New York RDP: What a Buffalo, NY Server Gets You

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 ✨