{"id":919,"date":"2026-10-25T03:00:00","date_gmt":"2026-10-25T03:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=919"},"modified":"2026-10-25T03:00:00","modified_gmt":"2026-10-25T03:00:00","slug":"change-hostname-rocky-linux-10","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/10\/25\/change-hostname-rocky-linux-10\/","title":{"rendered":"How to Change Hostname in Rocky Linux 10 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Change hostname on Rocky Linux 10 with <code>hostnamectl<\/code>, then make the new name resolve locally through <code>\/etc\/hosts<\/code>. The update takes about five minutes and becomes active immediately, with no reboot needed for the operating system itself.<\/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 10, preferably updated to the latest available 10.x release.<\/li>\n\n\n<li>An SSH session as <code>root<\/code>, or a normal account with working <code>sudo<\/code> privileges.<\/li>\n\n\n<li>A new short hostname such as <code>api01<\/code>, or an FQDN such as <code>api01.example.com<\/code>; use lowercase letters, numbers, hyphens, and dots.<\/li>\n\n\n<li>The server address shown by its default route, plus access to your DNS provider if other machines must resolve the FQDN.<\/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 the current name and server address<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Capture the existing identity before changing it so you can distinguish the saved hostname from a transient 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 --transient\nhostnamectl status --pretty\nip -4 route get 1.1.1.1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Rocky Linux 10 should appear in the release output. The static or pretty fields can be empty on a newly provisioned VPS. In the route result, note the value after <code>src<\/code>; that is the address to use as <code>SERVER_IP<\/code> in Step 3.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Rocky Linux release 10.2 (Red Quartz)\nold-api.example.com\n\nold-api\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 IP is documentation-only. Use the actual address returned by your VPS, not <code>203.0.113.40<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Set the persistent Rocky Linux hostname<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>hostnamectl<\/code> because it updates the running system and the 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 the same short name or FQDN you selected. Do not include spaces, underscores, or a trailing dot. For an FQDN, keep each label within DNS hostname limits and make sure the complete name is no longer than 64 characters for the system hostname.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The setter normally produces no output. The two checks should print the new value:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>api01.example.com\napi01.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Rocky\u2019s <a href=\"https:\/\/docs.rockylinux.org\/10\/books\/admin_guide\/12-network\/\" target=\"_blank\" rel=\"noopener\">hostname and networking documentation<\/a> uses <code>hostnamectl<\/code> for this change. You do not need to edit <code>\/etc\/hostname<\/code> by hand or restart <code>systemd-hostnamed<\/code> afterward.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you prefer to confirm the value through NetworkManager, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmcli general hostname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It should return the new static hostname. This command reads the setting; it is not a replacement for the <code>hostnamectl<\/code> command above.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Add a local hosts entry<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The static name and name resolution are separate: an <code>\/etc\/hosts<\/code> mapping lets local services find the VPS by its new FQDN before public DNS is available.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the file without disturbing the existing loopback and IPv6 records:<\/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 lines for <code>localhost<\/code> and <code>::1<\/code>. Replace an old machine-name line if one exists, or add this entry using the routed 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>api01.example.com<\/code> with short name <code>api01<\/code>, the finished line might be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>203.0.113.40 api01.example.com api01<\/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>api01<\/code>, use <code>SERVER_IP api01<\/code>. Keep one current machine-name line instead of leaving old and new entries together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Check the local resolver immediately:<\/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 should contain the server address and the new FQDN:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>203.0.113.40  api01.example.com api01\napi01.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This edit affects only the VPS. Create an A record for IPv4 or an AAAA record for IPv6 if the name must resolve from the public internet. Forward DNS and reverse DNS\/PTR are separate settings.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Check for hostname automation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Some cloud images run cloud-init or provider metadata at boot. Check for that before assuming the local change will survive a reboot.<\/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 cloud-init is absent, continue to Step 5. If it is installed and later restores the old name, create a drop-in that preserves the locally selected hostname, then 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 '%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\">The file-writing command should echo:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>preserve_hostname: true<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <a href=\"https:\/\/docs.cloud-init.io\/en\/latest\/reference\/modules.html\" target=\"_blank\" rel=\"noopener\">cloud-init module reference<\/a> documents <code>preserve_hostname<\/code>. If the VPS image still applies a provider-defined name, change that value in the provisioning or control-panel settings too.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Refresh shells and applications that cache the name<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The kernel and hostname service use the new name straight away, but an existing SSH prompt or long-running application may have loaded the old value when it started.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run a final service and file check:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl is-active systemd-hostnamed\nhostname\ncat \/etc\/hostname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected output is:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>active\napi01.example.com\napi01.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Open a second SSH session to refresh your shell prompt before closing the first one. Restart only a specific application that documents reading 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 a real unit name. Do not restart NetworkManager just to apply this hostname change, 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\">Use these checks together to validate the static setting, short form, FQDN resolution, and hosts-file entry:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostnamectl status --static\nhostname -s\nhostname --fqdn\ngetent hosts NEW_HOSTNAME\ngrep -nE '(^|[[:space:]])(OLD_HOSTNAME|NEW_HOSTNAME)([[:space:]]|$)' \/etc\/hosts<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For <code>api01.example.com<\/code>, the first three lines should be <code>api01.example.com<\/code>, <code>api01<\/code>, and <code>api01.example.com<\/code>. The <code>getent<\/code> result should show the intended address, and the final search should show the current hosts-file entry rather than an old name. Replace both uppercase hostname placeholders before running the <code>grep<\/code> command.<\/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 proposed static name contains an unsupported character, commonly a space, underscore, or trailing dot. Use lowercase letters, numbers, hyphens, and dots for <code>NEW_HOSTNAME<\/code>; reserve spaces for a 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 old 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 entry for the new FQDN. Keep the <code>localhost<\/code> records, replace the old machine-name mapping with <code>SERVER_IP NEW_HOSTNAME NEW_SHORT_NAME<\/code>, and rerun <code>getent hosts NEW_HOSTNAME<\/code>. If only remote computers see the old result, update public DNS instead.<\/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-provided metadata, or the VPS image is rewriting the name during startup. Check <code>cloud-init status --long<\/code>, add <code>preserve_hostname: true<\/code> when cloud-init is responsible, and update the provider-side hostname if its metadata continues to win.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The SSH prompt still shows the previous name<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The prompt was created before the change and may contain the old value even though <code>hostname<\/code> is current. Start a new SSH session; restart an individual service only if it caches the hostname at launch.<\/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 and test public A\/AAAA records from a separate network when the FQDN is 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 IP when reverse DNS matters.<\/li>\n\n\n<li>Update SSH inventory, monitoring, backups, certificates, and configuration-management records that still identify the server by its former 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 10 after changing the hostname?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>hostnamectl<\/code> changes the active name and writes the persistent hostname immediately. Start a new SSH session to refresh the prompt, and restart only applications that read the name once during startup.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Should I use a short hostname or an FQDN?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A short name such as <code>api01<\/code> is fine for a standalone VPS or private network. Use an FQDN when TLS, mail, monitoring, or multi-server administration needs a unique identity, and provide matching local or public DNS resolution.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does changing the hostname rename the VPS in the client area?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. This procedure changes the Rocky Linux guest operating system. A label in the VPSLake client area or Virtualizor is managed separately and does not automatically change when <code>\/etc\/hostname<\/code> changes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Is editing <code>\/etc\/hostname<\/code> directly recommended?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. Rocky Linux 10 uses systemd and NetworkManager to manage the system identity, so <code>hostnamectl<\/code> is the safer supported interface. Use <code>\/etc\/hosts<\/code> for local name resolution, but leave <code>\/etc\/hostname<\/code> to <code>hostnamectl<\/code>.<\/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 10 after changing the hostname?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. `hostnamectl` changes the active name and writes the persistent hostname immediately. Start a new SSH session to refresh the prompt, and restart only applications that read the name once during startup.\"}}, {\"@type\": \"Question\", \"name\": \"Should I use a short hostname or an FQDN?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"A short name such as `api01` is fine for a standalone VPS or private network. Use an FQDN when TLS, mail, monitoring, or multi-server administration needs a unique identity, and provide matching local or public DNS resolution.\"}}, {\"@type\": \"Question\", \"name\": \"Does changing the hostname rename the VPS in the client area?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. This procedure changes the Rocky Linux guest operating system. A label in the VPSLake client area or Virtualizor is managed separately and does not automatically change when `\/etc\/hostname` changes.\"}}, {\"@type\": \"Question\", \"name\": \"Is editing `\/etc\/hostname` directly recommended?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. Rocky Linux 10 uses systemd and NetworkManager to manage the system identity, so `hostnamectl` is the safer supported interface. Use `\/etc\/hosts` for local name resolution, but leave `\/etc\/hostname` to `hostnamectl`.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Change hostname on Rocky Linux 10 with hostnamectl, \/etc\/hosts, cloud-init checks, and clear verification steps for a persistent VPS name without rebooting.","protected":false},"author":1,"featured_media":920,"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,99],"class_list":["post-919","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-hostname","tag-linux-vps","tag-rocky-linux-10","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/919","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=919"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/919\/revisions"}],"predecessor-version":[{"id":3724,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/919\/revisions\/3724"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/920"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=919"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=919"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}