{"id":911,"date":"2026-10-24T03:00:00","date_gmt":"2026-10-24T03:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=911"},"modified":"2026-10-24T03:00:00","modified_gmt":"2026-10-24T03:00:00","slug":"change-hostname-almalinux-9","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/10\/24\/change-hostname-almalinux-9\/","title":{"rendered":"How to Change Hostname in AlmaLinux 9"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Change hostname in AlmaLinux 9 with <code>hostnamectl<\/code>, 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>AlmaLinux 9 on the VPS, with root access or a normal account that can use <code>sudo<\/code>.<\/li>\n\n\n<li>An active SSH connection and an editor such as <code>nano<\/code> or <code>vi<\/code>.<\/li>\n\n\n<li>A new short hostname such as <code>app01<\/code>, or an FQDN such as <code>app01.example.com<\/code>; use lowercase letters, digits, hyphens, and dots for the static name.<\/li>\n\n\n<li>The VPS&#8217;s primary IP address and access to your DNS provider if the new name must resolve outside this server.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> running AlmaLinux 9 if you need a fresh server for this change. Changing a hostname does not need extra RAM or disk space.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Inspect the current hostname<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/almalinux-release\nhostnamectl status --static\nhostnamectl status --pretty\nhostnamectl status --transient\nnmcli general hostname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AlmaLinux release 9.x\nold-app.example.com\nold-app.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The static hostname is the operating system&#8217;s durable name. Use a pretty hostname only as an optional human-readable label; it is not a DNS name.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Set the AlmaLinux 9 hostname<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>hostnamectl<\/code> updates the systemd hostname service and <code>\/etc\/hostname<\/code> through the supported interface, so you do not need to edit that file manually.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo hostnamectl set-hostname NEW_HOSTNAME<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>NEW_HOSTNAME<\/code> with <code>app01<\/code> or <code>app01.example.com<\/code>. The command normally prints nothing. Confirm the new static value and the file that stores it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostnamectl status --static\ncat \/etc\/hostname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app01.example.com\napp01.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you want a descriptive label as well, set it separately. Spaces are valid in a pretty hostname but not in the static hostname:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo hostnamectl set-hostname \"NEW_PRETTY_NAME\" --pretty\nhostnamectl status --pretty<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For example, <code>NEW_PRETTY_NAME<\/code> could be <code>Production application server<\/code>. AlmaLinux 9 activates the change through <code>systemd-hostnamed<\/code>; manually restarting that service is normally unnecessary. The <a href=\"https:\/\/docs.redhat.com\/en\/documentation\/red_hat_enterprise_linux\/9\/html\/configuring_and_managing_networking\/assembly_changing-a-hostname_configuring-and-managing-networking\" target=\"_blank\" rel=\"noopener\">RHEL 9 hostname documentation<\/a> describes the same hostname types and commands used by AlmaLinux 9.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Add local name resolution<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The hostname can be correct while lookups still return nothing, so add a local <code>\/etc\/hosts<\/code> record when the server or its services must resolve the name before DNS is available.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Identify the address used for the default IPv4 route:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ip -4 route get 1.1.1.1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Use the address after <code>src<\/code> as <code>SERVER_IP<\/code>. Open the hosts file and keep its existing <code>localhost<\/code> and IPv6 entries:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/hosts<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For an FQDN, add a line like this, replacing every uppercase placeholder:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SERVER_IP NEW_HOSTNAME NEW_SHORT_NAME<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>203.0.113.40 app01.example.com app01<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you chose only <code>app01<\/code>, use <code>SERVER_IP app01<\/code> instead. Save the file, then test the system resolver and the fully qualified result:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>getent hosts NEW_HOSTNAME\nhostname --fqdn<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Successful output resembles:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>203.0.113.40  app01.example.com app01\napp01.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Use NetworkManager instead<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">AlmaLinux 9 uses NetworkManager, so <code>nmcli<\/code> 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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Display and set the NetworkManager hostname:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmcli general hostname\nsudo nmcli general hostname NEW_HOSTNAME\nnmcli general hostname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The final command should print the new name:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app01.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For a menu-driven terminal interface, install the optional package and launch it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y NetworkManager-tui\nsudo nmtui<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Choose <strong>Set system hostname<\/strong>, enter the static hostname, select <strong>OK<\/strong>, and then choose <strong>Quit<\/strong>. <code>nmtui<\/code> changes the system hostname but does not create DNS records or edit <code>\/etc\/hosts<\/code>, so complete Step 3 when local resolution is required.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Refresh the session and affected services<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check the hostname service and persistent file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl is-active systemd-hostnamed\ncat \/etc\/hostname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>active\napp01.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Reconnect over SSH to refresh the shell prompt. Restart an application only if it caches the hostname at startup, using its actual unit name:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl restart YOUR_SERVICE<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>YOUR_SERVICE<\/code> 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the new hostname<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Run these checks as a final pass. They confirm the persistent name, optional label, local FQDN result, and resolver mapping:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostnamectl status --static\nhostnamectl status --pretty\nhostname --fqdn\ngetent hosts NEW_HOSTNAME<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The static hostname and <code>hostname --fqdn<\/code> result should match your chosen name. The pretty value is blank unless you set one, and <code>getent<\/code> should return the expected server address. If DNS is already configured, the final result can come from DNS instead of <code>\/etc\/hosts<\/code>.<\/p>\n\n\n\n<aside class=\"vl-element vl-cta-banner\" aria-label=\"Give your server a clear identity\">\n\t<div class=\"vl-cta-banner__content\">\n\t\t<p class=\"vl-cta-banner__eyebrow\">AlmaLinux VPS<\/p>\n\t\t<h3 class=\"vl-cta-banner__title\">Give your server a clear identity<\/h3>\n\t\t<p class=\"vl-cta-banner__text\">Deploy an AlmaLinux VPS with root access for fast hostname and network configuration.<\/p>\n\t<\/div>\n\t<a class=\"vl-cta-banner__button\" href=\"\/buy-vps\" aria-label=\"View Linux VPS plans\">View Linux VPS plans<\/a>\n<\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">The SSH prompt still shows the old name<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>hostname --fqdn<\/code> returns the old name<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The static setting is new, but <code>\/etc\/hosts<\/code> or DNS still gives the old answer. Search the local file for stale entries, remove or update the old hostname mapping, then rerun <code>getent hosts NEW_HOSTNAME<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -nE 'OLD_HOSTNAME|NEW_HOSTNAME' \/etc\/hosts\ngetent hosts NEW_HOSTNAME<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The hostname changes back after a reboot<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Cloud-init, DHCP, or the VPS image&#8217;s provisioning settings may be applying a name during boot. Check whether cloud-init is installed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rpm -q cloud-init<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If it is installed and you want to preserve the manual hostname, create a cloud-init override and set the name again:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo install -d -m 0755 \/etc\/cloud\/cloud.cfg.d\nprintf 'preserve_hostname: true\\n' | sudo tee \/etc\/cloud\/cloud.cfg.d\/99-preserve-hostname.cfg\nsudo hostnamectl set-hostname NEW_HOSTNAME<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the provider&#8217;s provisioning process still replaces it, update the hostname in the VPS provisioning or control-panel settings too.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>nmtui: command not found<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The text interface is optional on minimal AlmaLinux 9 installations. Install <code>NetworkManager-tui<\/code> with <code>dnf<\/code>, or skip the menu and use <code>hostnamectl<\/code>, which is the simpler choice for a remote SSH session.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Can I use a short hostname without owning a domain?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. A name such as <code>app01<\/code> 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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does changing the hostname rename my VPS in the control panel?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>hostnamectl<\/code> changes the AlmaLinux operating system&#8217;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.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should I edit <code>\/etc\/hostname<\/code> directly?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Usually not. <code>hostnamectl<\/code> writes the persistent file and activates the running hostname together, reducing the chance that the file and the current system state disagree.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Will changing the hostname interrupt my SSH connection?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"Can I use a short hostname without owning a domain?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"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.\"}}, {\"@type\": \"Question\", \"name\": \"Does changing the hostname rename my VPS in the control panel?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"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.\"}}, {\"@type\": \"Question\", \"name\": \"Should I edit `\/etc\/hostname` directly?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"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.\"}}, {\"@type\": \"Question\", \"name\": \"Will changing the hostname interrupt my SSH connection?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"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.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"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.","protected":false},"author":1,"featured_media":912,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"csco_singular_sidebar":"","csco_page_header_type":"","csco_page_load_nextpost":"","footnotes":""},"categories":[5,9],"tags":[95,106,93],"class_list":["post-911","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-almalinux-9","tag-hostname","tag-linux-vps","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/911","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/comments?post=911"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/911\/revisions"}],"predecessor-version":[{"id":3710,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/911\/revisions\/3710"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/912"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=911"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=911"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=911"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}