{"id":923,"date":"2026-10-25T13:00:00","date_gmt":"2026-10-25T13:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=923"},"modified":"2026-10-25T13:00:00","modified_gmt":"2026-10-25T13:00:00","slug":"change-hostname-rocky-linux-9","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/10\/25\/change-hostname-rocky-linux-9\/","title":{"rendered":"How to Change Hostname in Rocky Linux 9 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Change hostname in Rocky Linux 9 with <code>hostnamectl<\/code>, a local <code>\/etc\/hosts<\/code> mapping, and checks for NetworkManager or cloud-init overrides. The new name becomes active immediately, and the complete setup usually takes about five minutes without 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>A VPS running Rocky Linux 9, preferably updated to the latest available 9.x release.<\/li>\n\n\n<li>An SSH session as <code>root<\/code>, or a normal user with working <code>sudo<\/code> privileges.<\/li>\n\n\n<li>A short name such as <code>web01<\/code>, or an FQDN such as <code>web01.example.com<\/code>; use lowercase letters, numbers, hyphens, and dots for the static hostname.<\/li>\n\n\n<li>The server&#8217;s primary IPv4 address and access to your DNS provider if other systems must resolve the FQDN.<\/li>\n\n\n<li>No additional RAM or disk space is needed 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: Inspect the current Rocky Linux name<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Record the current values first so you can separate the saved hostname from a transient name supplied by networking 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\nip -4 route get 1.1.1.1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The release line should identify Rocky Linux 9. A blank pretty or transient value is normal on some VPS images. In the route output, note the address after <code>src<\/code>; use that value as <code>SERVER_IP<\/code> later.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Rocky Linux release 9.x (Blue Onyx)\nold-web.example.com\n\nold-web.example.com\nold-web.example.com\n1.1.1.1 via 203.0.113.1 dev ens3 src 203.0.113.40 uid 0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The example address is documentation-only. Substitute the real address returned by your VPS rather than <code>203.0.113.40<\/code>.<\/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> because it changes the running system and writes Rocky Linux&#8217;s persistent <code>\/etc\/hostname<\/code> value through <code>systemd-hostnamed<\/code>.<\/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 name such as <code>web01<\/code> or <code>web01.example.com<\/code>. Do not include spaces, underscores, or a trailing dot. The setter normally prints nothing; both checks should now return the new static 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 readable label for administrators, set the optional pretty hostname separately. It can contain spaces, but it is not the machine name used for DNS:<\/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 web server<\/code>. Rocky Linux 9 uses the same hostname types and <code>hostnamectl<\/code> workflow described in 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>.<\/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\">Changing the system identity does not publish DNS, so add a local hosts entry when services on the VPS need to resolve the new FQDN reliably.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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 lines. Replace an old machine-name line if one exists, or add this line using the <code>src<\/code> address from Step 1:<\/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>, the short alias is <code>web01<\/code>, so a completed entry could look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>203.0.113.40 web01.example.com web01<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>SERVER_IP<\/code>, <code>NEW_HOSTNAME<\/code>, and <code>NEW_SHORT_NAME<\/code> with your values before saving. If you chose only <code>web01<\/code>, use <code>SERVER_IP web01<\/code>. Keep one current machine-name entry instead of leaving old and new mappings together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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 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\">This mapping affects the VPS only. Create an A record for IPv4 or an AAAA record for IPv6 with your DNS provider when the hostname must work from other computers. Forward DNS and reverse DNS are separate settings.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Check NetworkManager and hostname automation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Rocky Linux 9 uses NetworkManager for network management, so compare its hostname view with the value you just set:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmcli general hostname\nsystemctl is-active NetworkManager\nsystemctl is-active systemd-hostnamed<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The first command should print <code>NEW_HOSTNAME<\/code>; both service checks should print <code>active<\/code> on a normally running VPS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>web01.example.com\nactive\nactive<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">NetworkManager&#8217;s Rocky Linux 9 role and configuration model are covered in the <a href=\"https:\/\/docs.rockylinux.org\/9\/guides\/network\/basic_network_configuration\/\" target=\"_blank\" rel=\"noopener\">Rocky Linux 9 network configuration guide<\/a>. You do not need to restart either service just because <code>hostnamectl<\/code> succeeded.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Some VPS images also run cloud-init and may restore a provider-supplied name during boot. Check for it before changing configuration:<\/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 remains correct after a reboot, leave cloud-init unchanged. If it restores the old name, preserve the local setting and apply 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 '%s\\n' 'preserve_hostname: true' | 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\">Use the same <code>NEW_HOSTNAME<\/code> value from Step 2. The <code>tee<\/code> command should echo <code>preserve_hostname: true<\/code>. If provider metadata continues to overwrite the name, update that provisioning value as well.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Refresh SSH and applications<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The kernel uses the new name immediately, but an existing shell prompt or long-running application may have read the old name when it started.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm the active name and the persistent file, then open a second SSH session:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostname\nhostnamectl status --static\ncat \/etc\/hostname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">All three lines should contain the new hostname:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>web01.example.com\nweb01.example.com\nweb01.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Reconnect over SSH to refresh the prompt before closing the original session. Restart a specific application only if it caches the hostname at startup:<\/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 the actual unit name. A hostname change alone does not require restarting networking or rebooting the VPS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Verify the new Rocky Linux 9 hostname<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Run this final set to validate the static value, short form, FQDN lookup, and NetworkManager&#8217;s view:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostnamectl status --static\nhostname -s\nhostname --fqdn\nnmcli general hostname\ngetent hosts NEW_HOSTNAME<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For <code>web01.example.com<\/code>, the first four lines should be the FQDN, <code>web01<\/code>, the FQDN again, and the FQDN again. The last line should return the address and aliases from <code>\/etc\/hosts<\/code> or the expected DNS answer. When those values agree, Rocky Linux 9 is using the new hostname locally.<\/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\">Rocky Linux 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 a Rocky Linux VPS with root access for reliable hostname and DNS 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 name contains a character Rocky Linux rejects, usually a space, underscore, or trailing dot. Use lowercase letters, numbers, hyphens, and dots in <code>NEW_HOSTNAME<\/code>; put spaces only in the separate pretty hostname. Check that every 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 previous name<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The operating-system name changed, but <code>\/etc\/hosts<\/code> still has a stale machine entry or no mapping for the new FQDN. Keep the 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 result, update public DNS instead of this file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>nmcli general hostname<\/code> shows a different value<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">NetworkManager or provisioning metadata is still supplying another hostname. Re-run <code>sudo hostnamectl set-hostname NEW_HOSTNAME<\/code>, check the output of <code>nmcli general hostname<\/code>, and inspect cloud-init as shown in Step 4. Do not edit NetworkManager connection files by hand for this change.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The old hostname returns after reboot<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Cloud-init, DHCP metadata, or the VPS image&#8217;s provisioning settings are applying a name at boot. If cloud-init is responsible, add <code>99-preserve-hostname.cfg<\/code> from Step 4 and set the name again; if the provider still wins, change the hostname in its provisioning settings.<\/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>Create and test the public A or AAAA record from another network if the name will be used for TLS, mail, monitoring, or a website.<\/li>\n\n\n<li>Request a matching PTR record through the service that manages the VPS address when reverse DNS matters.<\/li>\n\n\n<li>Update SSH inventory, monitoring, backup jobs, 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\">Does changing the hostname change my Rocky Linux VPS IP address?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. The procedure changes the guest operating system&#8217;s identity, not its network interface, route, or assigned address. DNS records still need to point the chosen name at the correct IP address.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Do I need <code>nmtui<\/code> to rename a Rocky Linux 9 server?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>hostnamectl<\/code> is sufficient for a normal SSH-based rename, and <code>nmcli general hostname<\/code> lets you check NetworkManager&#8217;s view. <code>nmtui<\/code> is an optional text menu for broader NetworkManager configuration, not a requirement for this task.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can the hostname contain an underscore?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Do not use underscores in the static hostname. Choose DNS-safe labels made from letters, numbers, hyphens, and dots; use the separate pretty hostname if you need spaces or a descriptive label.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why does my current SSH prompt still show the old name?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Shell prompts are often assembled when the session starts, so an existing terminal can retain the earlier value even though the system has changed. Open a new SSH session, and restart only applications that cache the hostname at launch.<\/p>\n\n\n\n<script type=\"application\/ld+json\">{\"@context\": \"https:\/\/schema.org\", \"@type\": \"FAQPage\", \"mainEntity\": [{\"@type\": \"Question\", \"name\": \"Does changing the hostname change my Rocky Linux VPS IP address?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. The procedure changes the guest operating system's identity, not its network interface, route, or assigned address. DNS records still need to point the chosen name at the correct IP address.\"}}, {\"@type\": \"Question\", \"name\": \"Do I need `nmtui` to rename a Rocky Linux 9 server?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. `hostnamectl` is sufficient for a normal SSH-based rename, and `nmcli general hostname` lets you check NetworkManager's view. `nmtui` is an optional text menu for broader NetworkManager configuration, not a requirement for this task.\"}}, {\"@type\": \"Question\", \"name\": \"Can the hostname contain an underscore?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Do not use underscores in the static hostname. Choose DNS-safe labels made from letters, numbers, hyphens, and dots; use the separate pretty hostname if you need spaces or a descriptive label.\"}}, {\"@type\": \"Question\", \"name\": \"Why does my current SSH prompt still show the old name?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Shell prompts are often assembled when the session starts, so an existing terminal can retain the earlier value even though the system has changed. Open a new SSH session, and restart only applications that cache the hostname at launch.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Change hostname in Rocky Linux 9 with hostnamectl, NetworkManager, \/etc\/hosts, and cloud-init checks, then verify the new name without rebooting.","protected":false},"author":1,"featured_media":924,"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,100],"class_list":["post-923","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-hostname","tag-linux-vps","tag-rocky-linux-9","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/923","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=923"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/923\/revisions"}],"predecessor-version":[{"id":3729,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/923\/revisions\/3729"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/924"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}