{"id":921,"date":"2026-10-25T09:00:00","date_gmt":"2026-10-25T09:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=921"},"modified":"2026-10-25T09:00:00","modified_gmt":"2026-10-25T09:00:00","slug":"change-hostname-rocky-linux-8","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/10\/25\/change-hostname-rocky-linux-8\/","title":{"rendered":"How to Change Hostname in Rocky Linux 8 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Change hostname in Rocky Linux 8 with <code>hostnamectl<\/code>, then make the new name resolve locally through <code>\/etc\/hosts<\/code>. The active name changes in seconds, and you can finish the configuration in about five minutes without rebooting the VPS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>A VPS running Rocky Linux 8.<\/li>\n\n\n<li>An SSH connection as <code>root<\/code>, or a normal account with working <code>sudo<\/code> privileges.<\/li>\n\n\n<li>A short hostname such as <code>web01<\/code>, or an FQDN such as <code>web01.example.com<\/code>; use lowercase letters, numbers, hyphens, and dots.<\/li>\n\n\n<li>The VPS&#8217;s primary IP address and access to your DNS provider if other computers must resolve the FQDN.<\/li>\n\n\n<li>No special RAM or disk allocation is required for a hostname change.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> if you need a Rocky Linux server with root access.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Record Rocky Linux 8&#8217;s current name<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Check the different hostname types first so you can distinguish the saved system name from a temporary value supplied by DHCP or provisioning.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/rocky-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 command should identify Rocky Linux 8. A blank pretty or transient value is normal on some minimal images. Example output might look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Rocky Linux release 8.x (Green Obsidian)\nold-web.example.com\n\nold-web.example.com\nold-web.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The static hostname is the durable machine identity. The pretty hostname is only an optional human-readable label, while the transient value can come from the network.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Set the persistent hostname<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>hostnamectl<\/code> so systemd updates the active kernel name and Rocky Linux&#8217;s <code>\/etc\/hostname<\/code> together.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo hostnamectl set-hostname NEW_HOSTNAME\nhostnamectl status --static\ncat \/etc\/hostname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>NEW_HOSTNAME<\/code> with a short name such as <code>web01<\/code> or an FQDN such as <code>web01.example.com<\/code>. Do not use spaces, underscores, or a trailing dot. The command normally returns no success message; both checks should print the new name:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>web01.example.com\nweb01.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you want a descriptive label for administrators, set a pretty hostname separately. It may contain spaces and does not replace the operational name:<\/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\">Replace <code>NEW_PRETTY_NAME<\/code> with a label such as <code>Production web server<\/code>. The hostnamectl procedure in the <a href=\"https:\/\/docs.redhat.com\/en\/documentation\/red_hat_enterprise_linux\/8\/html\/configuring_and_managing_networking\/assembly_changing-a-hostname_configuring-and-managing-networking\" target=\"_blank\" rel=\"noopener\">RHEL 8 networking documentation<\/a> applies to Rocky Linux 8&#8217;s compatible systemd and NetworkManager stack.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Make the new name resolve on the VPS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Changing the system name does not create DNS records, so add a local hosts entry when the server must resolve its own FQDN before public DNS is ready or whenever local-only resolution is sufficient.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Find the IPv4 address used by the default 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 shown after <code>src<\/code> as <code>SERVER_IP<\/code>. Then open the hosts file:<\/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\">Keep the existing <code>localhost<\/code> and IPv6 entries. Add one line for the server, replacing the uppercase placeholders:<\/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 <code>web01.example.com<\/code>, <code>NEW_SHORT_NAME<\/code> is <code>web01<\/code>. If you chose only a short hostname, use <code>SERVER_IP web01<\/code> instead. Save the file, then test the local resolver:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>getent hosts NEW_HOSTNAME\nhostname --fqdn\nhostname -s<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Successful output for an FQDN resembles:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>203.0.113.40  web01.example.com web01\nweb01.example.com\nweb01<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The hosts file changes this VPS only. Create an A or AAAA record with your DNS provider if the name must work from other machines. A forward DNS record also does not automatically create reverse DNS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Apply the name through NetworkManager when needed<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Rocky Linux 8 commonly uses NetworkManager, so <code>nmcli<\/code> gives you a second supported way to inspect or set the system hostname and helps reveal a provisioning conflict.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Display the current NetworkManager value and set it if it differs from the value in Step 2:<\/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\">Replace <code>NEW_HOSTNAME<\/code> with the same static name used earlier. The final command should return it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>web01.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For a menu-driven terminal interface, install the optional package and open 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 new value, select <strong>OK<\/strong>, and choose <strong>Quit<\/strong>. <code>nmtui<\/code> changes the system hostname but does not edit <code>\/etc\/hosts<\/code> or publish DNS, so keep the local mapping from Step 3 when you need it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Prevent an image from restoring the old name<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Some VPS images use cloud-init or provider metadata at boot. Check for cloud-init before changing its configuration; installing it is not necessary for an ordinary hostname update.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if command -v cloud-init &gt;\/dev\/null 2&gt;&amp;1; then\n  cloud-init status --long\nelse\n  echo \"cloud-init is not installed\"\nfi<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the hostname survives a reboot, no change is needed. If cloud-init restores the previous name, create a drop-in that preserves the local value 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\nsudo tee \/etc\/cloud\/cloud.cfg.d\/99-preserve-hostname.cfg &gt;\/dev\/null &lt;&lt;'EOF'\npreserve_hostname: true\nEOF\nsudo hostnamectl set-hostname NEW_HOSTNAME<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>NEW_HOSTNAME<\/code> with the desired name. If the provider continues to apply a value from instance metadata, change that provisioning value as well; otherwise it can overwrite the local configuration on a later boot.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the new Rocky Linux 8 hostname<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Run the checks below together. They confirm the static value, NetworkManager&#8217;s view, the persistent file, and the resolver result.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostnamectl status --static\nnmcli general hostname\ncat \/etc\/hostname\nhostname --fqdn\ngetent hosts NEW_HOSTNAME<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For an FQDN, the first three lines should show the same name, <code>hostname --fqdn<\/code> should return that FQDN, and <code>getent<\/code> should return the expected server address. If the pretty hostname was set, check it separately:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostnamectl status --pretty\nsystemctl is-active systemd-hostnamed<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected output is similar to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Production web server\nactive<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The change is active immediately. Reconnect over SSH to refresh a prompt that still displays the old name, and restart only an application that reads the hostname once during startup.<\/p>\n\n\n\n<aside class=\"vl-element vl-cta-banner\" aria-label=\"Choose your server name\">\n\t<div class=\"vl-cta-banner__content\">\n\t\t<p class=\"vl-cta-banner__eyebrow\">Rocky Linux VPS<\/p>\n\t\t<h3 class=\"vl-cta-banner__title\">Choose your server name<\/h3>\n\t\t<p class=\"vl-cta-banner__text\">Deploy a Rocky Linux VPS with root access for a clean hostname and network setup.<\/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\"><code>hostnamectl: invalid hostname<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The static value contains a space, underscore, trailing dot, or another unsupported character. Use lowercase letters, digits, hyphens, and dots for <code>NEW_HOSTNAME<\/code>; put spaces only in the separate <code>--pretty<\/code> value. Check that each FQDN label starts and ends with a letter or number.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>hostname --fqdn<\/code> returns <code>localhost<\/code> or the old name<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The system hostname changed, but <code>\/etc\/hosts<\/code> still has a stale mapping or no entry for the new name. Keep the existing localhost records, replace the old server line with <code>SERVER_IP NEW_HOSTNAME NEW_SHORT_NAME<\/code>, and run <code>getent hosts NEW_HOSTNAME<\/code> again. If only remote systems see the old value, update public DNS rather than editing this VPS&#8217;s hosts file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The old hostname comes back after reboot<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Cloud-init, DHCP, or provider metadata is applying a name during boot. Check <code>cloud-init status --long<\/code>, add <code>99-preserve-hostname.cfg<\/code> from Step 5 if cloud-init is responsible, and update the hostname in the VPS provisioning settings if metadata still wins.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>nmcli: command not found<\/code> or <code>nmtui: command not found<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>hostnamectl<\/code> is sufficient and is normally already installed. On a minimal Rocky Linux image, install the missing NetworkManager tools with <code>sudo dnf install -y NetworkManager NetworkManager-tui<\/code>, then retry the command.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Next steps<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>Add the public A or AAAA record and test it from a different network if the FQDN will be used for websites, certificates, mail, or monitoring.<\/li>\n\n\n<li>Request a matching PTR record through the system that manages the VPS address when reverse DNS matters.<\/li>\n\n\n<li>Update SSH inventory, monitoring, backups, certificates, and configuration-management records that still contain the old name.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Do I need to reboot Rocky Linux 8 after changing the hostname?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>hostnamectl<\/code> updates the active hostname and <code>\/etc\/hostname<\/code> immediately. Reconnect to refresh your shell prompt, and restart only a service that caches the name at startup.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Is <code>nmcli<\/code> better than <code>hostnamectl<\/code> on Rocky Linux 8?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Both are supported on Rocky Linux 8. <code>hostnamectl<\/code> is the simplest choice for a one-time rename, while <code>nmcli general hostname<\/code> is useful for checking what NetworkManager currently stores on a server managed through NetworkManager.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I change the hostname without changing the server&#8217;s IP address?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. A hostname change does not alter network interfaces, routes, or IP addresses. If the new name is an FQDN, create its DNS record separately and make sure local resolution matches it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is the difference between a static, transient, and pretty hostname?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The static hostname is the persistent machine name stored in <code>\/etc\/hostname<\/code>. A transient name may be supplied by the network, while a pretty hostname is an optional descriptive label that can contain spaces and is not used as the server&#8217;s DNS identity.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"Do I need to reboot Rocky Linux 8 after changing the hostname?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. `hostnamectl` updates the active hostname and `\/etc\/hostname` immediately. Reconnect to refresh your shell prompt, and restart only a service that caches the name at startup.\"}}, {\"@type\": \"Question\", \"name\": \"Is `nmcli` better than `hostnamectl` on Rocky Linux 8?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Both are supported on Rocky Linux 8. `hostnamectl` is the simplest choice for a one-time rename, while `nmcli general hostname` is useful for checking what NetworkManager currently stores on a server managed through NetworkManager.\"}}, {\"@type\": \"Question\", \"name\": \"Can I change the hostname without changing the server's IP address?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. A hostname change does not alter network interfaces, routes, or IP addresses. If the new name is an FQDN, create its DNS record separately and make sure local resolution matches it.\"}}, {\"@type\": \"Question\", \"name\": \"What is the difference between a static, transient, and pretty hostname?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"The static hostname is the persistent machine name stored in `\/etc\/hostname`. A transient name may be supplied by the network, while a pretty hostname is an optional descriptive label that can contain spaces and is not used as the server's DNS identity.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Change hostname in Rocky Linux 8 with hostnamectl, NetworkManager, local DNS mapping, and cloud-init checks, then verify it without a reboot.","protected":false},"author":1,"featured_media":922,"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":[106,93,105],"class_list":["post-921","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-hostname","tag-linux-vps","tag-rocky-linux-8","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/921","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=921"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/921\/revisions"}],"predecessor-version":[{"id":3728,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/921\/revisions\/3728"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/922"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}