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

change hostname on almalinux 10 with hostnamectl, update local name resolution, prevent cloud-init resets, and verify the new name without rebooting.
A polished blue-lit server connected to a glowing network orb in a midnight-blue data center.

Change hostname on AlmaLinux 10 with hostnamectl, a local /etc/hosts entry, and a quick verification pass. You can finish the change in about five minutes without rebooting, although long-running services may need a restart or a new SSH session.

Prerequisites

  • An AlmaLinux 10 VPS with root access or a regular account that can run commands with sudo.
  • An SSH client connected to the server; the commands below are designed for a headless installation.
  • A hostname that uses letters, numbers, hyphens, and dots; use an FQDN such as app01.example.com if the server has a domain name.
  • If you plan to use an FQDN, access to the domain’s DNS records and the VPS’s primary IP address.
  • A VPSLake Linux VPS running AlmaLinux 10 if you need a server for this procedure.

Step 1: Inspect the current hostname

Record the existing values first so you can identify whether the server currently has a static, pretty, or transient name.

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

On a new VPS, the static and pretty values may be empty while the transient value comes from the image or network configuration:

AlmaLinux release 10.x
old-server.example.net
old-server.example.net
old-server

An empty line is normal when a particular hostname type has not been configured. The static hostname is the important value for the operating system and most services.

Step 2: Set the new static hostname

Use hostnamectl so systemd, /etc/hostname, and the running kernel receive the change through the supported interface.

sudo hostnamectl set-hostname NEW_HOSTNAME

Replace NEW_HOSTNAME with the name you chose, such as app01.example.com or app01. A static hostname cannot contain spaces. AlmaLinux accepts an FQDN, but each DNS label should be no longer than 63 characters and the complete name should stay within normal hostname limits.

If you also want a human-readable description, set the optional pretty hostname separately. It may contain spaces and does not replace the machine’s static name:

sudo hostnamectl set-hostname "NEW_PRETTY_NAME" --pretty

Replace NEW_PRETTY_NAME with a description such as Production application server. The command normally produces no output; check the result with:

hostnamectl status --static
hostnamectl status --pretty

Expected output is similar to:

app01.example.com
Production application server

According to the RHEL 10 hostname documentation, hostnamectl activates the new value through systemd-hostnamed, so manually restarting that service is normally unnecessary.

Step 3: Add local name resolution

An /etc/hosts entry lets the VPS resolve its own name even when DNS is unavailable during boot or when the DNS record has not propagated yet.

First identify the address used by the default route:

ip -4 route get 1.1.1.1

Look for the src value in the output. It is the server address to use as SERVER_IP. Open the hosts file:

sudo nano /etc/hosts

Keep the existing localhost and IPv6 lines. Add one line using your actual address, the FQDN, and its short alias:

SERVER_IP NEW_HOSTNAME NEW_SHORT_NAME

For example, if the address is 203.0.113.40 and the hostname is app01.example.com, the line would be 203.0.113.40 app01.example.com app01. Replace all three uppercase placeholders before saving. If you selected only a short hostname, use SERVER_IP NEW_HOSTNAME instead. Do not replace the localhost records with the new name.

Test the mapping immediately:

getent hosts NEW_HOSTNAME
hostname --fqdn

Successful output contains the server address and the new name:

203.0.113.40  app01.example.com
app01.example.com

If your hostname is public, also create the matching A or AAAA record in DNS. The hosts file affects this VPS only; it does not publish the name to the rest of the internet.

Step 4: Use NetworkManager’s text interface instead

The command line is quickest, but nmtui is useful when you prefer a guided terminal menu or need to set the name while reviewing NetworkManager settings.

Install the optional text interface if it is not already present:

sudo dnf install -y NetworkManager-tui

Start it:

sudo nmtui

Choose Set system hostname, enter the new static hostname, select OK, then choose Quit. nmtui changes the same system hostname managed by hostnamectl; it does not create public DNS records or update /etc/hosts for you. Repeat Step 3 when local resolution is needed.

Step 5: Refresh sessions and dependent services

The hostname changes immediately for new commands, but an existing shell prompt or service may still display the old value until it is restarted.

Confirm that the hostname service is active and that the persistent file contains the new value:

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

Expected output is:

active
app01.example.com

Reconnect through SSH to refresh your shell prompt. Restart only applications that read the hostname once at startup, using that application’s service name; do not restart NetworkManager just to apply this hostname change:

sudo systemctl restart YOUR_SERVICE

Replace YOUR_SERVICE with a real service only when that application requires it. A reboot is optional, not part of the normal hostname change.

Verify the new hostname

Run all four checks after editing the name. They confirm the static value, optional pretty value, fully qualified result, and local resolver mapping:

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

The static and FQDN checks should show your new hostname, while the pretty check should show the description only if you set one. getent should return the address from your /etc/hosts line or from DNS. If all four results agree, AlmaLinux 10 is using the new identity correctly.

Troubleshooting

The hostname returns after a reboot

The image’s provisioning system, DHCP, or cloud-init may be applying its own name during boot. Check whether cloud-init is installed and whether it reports an active configuration:

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

If cloud-init manages this server and you want to keep a manually chosen hostname, create a cloud-init override, set the hostname again, and apply the next reboot during a maintenance window:

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

If the VPS image or provider still overwrites the name, change the hostname in the provisioning settings as well.

hostnamectl: invalid hostname

Static hostnames cannot contain spaces, underscores, or other punctuation. Use lowercase letters, numbers, hyphens, and dots; set a description with --pretty if you need spaces. Also check that no FQDN label begins or ends with a hyphen.

hostname --fqdn shows localhost or fails to resolve

The static hostname is set, but local resolution is incomplete. Add the server’s real address, FQDN, and short alias to /etc/hosts as shown in Step 3, then run getent hosts NEW_HOSTNAME again. If the name should work from other machines too, add its A or AAAA record to DNS.

nmtui: command not found

nmtui is an optional NetworkManager package and is not present on every minimal AlmaLinux image. Install NetworkManager-tui with dnf, or skip the menu and use hostnamectl, which is already part of the standard systemd tools.

Next steps

  • Create forward DNS records for the FQDN and verify them from another machine with getent hosts NEW_HOSTNAME or a DNS lookup tool.
  • Set a matching reverse-DNS/PTR record in the VPS control panel if mail, monitoring, or an external security service checks reverse DNS.
  • Reconnect your SSH client and update monitoring, backup, and configuration-management inventory if they identify the server by hostname.

FAQ

Do I need to reboot AlmaLinux 10 after changing the hostname?

No. hostnamectl applies the static hostname immediately and writes the persistent hostname file. Reconnect your SSH session and restart only services that cache the name at startup.

Should I use a short hostname or an FQDN?

Use a short name for a simple private server, or an FQDN when the VPS has a domain and services need a stable DNS identity. An FQDN is useful for TLS, mail, monitoring, and multi-server administration, but it still needs DNS or an /etc/hosts entry to resolve.

Does changing the hostname change DNS or reverse DNS?

No. The change affects the local operating system only. Add the forward DNS record separately, and configure the PTR record through the system that manages your VPS IP address.

What is the difference between a static and pretty hostname?

The static hostname is the machine’s operational name and is stored in /etc/hostname. A pretty hostname is an optional descriptive label for people; it can contain spaces and does not replace the static value used by services.

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 Add Swap Space on Rocky Linux 8 (Step-by-Step)

Next Article

How to Buy Windows RDP: Order to Login

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 ✨