{"id":931,"date":"2026-10-26T13:00:00","date_gmt":"2026-10-26T13:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=931"},"modified":"2026-10-26T13:00:00","modified_gmt":"2026-10-26T13:00:00","slug":"change-hostname-ubuntu-26-04","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/10\/26\/change-hostname-ubuntu-26-04\/","title":{"rendered":"How to Change Hostname on Ubuntu 26.04 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Change hostname on Ubuntu 26.04 with <code>hostnamectl<\/code>, a matching <code>\/etc\/hosts<\/code> entry, and a few focused checks. You can normally finish in about five minutes without rebooting, then reconnect over SSH to see the new name in your prompt.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n\n<li>Ubuntu Server 26.04 LTS (Resolute) running on the VPS.<\/li>\n\n\n<li>An SSH session as <code>root<\/code>, or a regular user with working <code>sudo<\/code> privileges.<\/li>\n\n\n<li>A short hostname such as <code>web03<\/code>, or an FQDN such as <code>web03.example.com<\/code>; use lowercase letters, numbers, hyphens, and dots only.<\/li>\n\n\n<li>The server&#8217;s address if you want a local <code>\/etc\/hosts<\/code> mapping, plus access to your DNS provider if other systems must resolve the FQDN.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> with root access if you need an Ubuntu 26.04 server for this procedure.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Record the current hostname<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Check the active, persistent, and resolver-facing values first so you can spot a stale name after the edit.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/os-release\nhostnamectl --static\nhostnamectl --transient\nhostnamectl --pretty\nhostname\ncat \/etc\/hostname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The release file should identify Ubuntu 26.04 LTS (Resolute). Empty transient or pretty values are normal; the static value is the name saved for future boots.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"Ubuntu 26.04 LTS (Resolute Raccoon)\"\nold-web.example.com\nold-web.example.com\nold-web.example.com\nold-web.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The exact release string can vary with the image&#8217;s update level. The important part is that the OS is Ubuntu 26.04 and you have noted the old hostname before changing it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Set the new static hostname<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>hostnamectl<\/code> changes the running hostname and writes the persistent system value through systemd, so you do not need to edit <code>\/etc\/hostname<\/code> by hand.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo hostnamectl set-hostname NEW_HOSTNAME\nhostnamectl --static<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>NEW_HOSTNAME<\/code> with a short name such as <code>web03<\/code> or an FQDN such as <code>web03.example.com<\/code>. Do not use spaces, underscores, a trailing dot, or a name longer than 64 characters. The command normally prints nothing; the second command should show your new value:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>web03.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ubuntu&#8217;s <code>hostnamectl<\/code> distinguishes static, transient, and pretty names. The static name is the operational identity used at boot; a pretty name is optional and can contain spaces, but it is not a substitute for the static hostname. See the <a href=\"https:\/\/manpages.ubuntu.com\/manpages\/resolute\/man1\/hostnamectl.1.html\" target=\"_blank\" rel=\"noopener\">Ubuntu 26.04 hostnamectl manual<\/a> for these hostname types and their limits.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Make the new name resolve locally<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Changing the system name does not automatically make <code>hostname --fqdn<\/code> resolve, so update Ubuntu&#8217;s local hosts record as well.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Open the 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 records. Replace the old machine-name line or add one <code>127.0.1.1<\/code> line. For an FQDN, use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>127.0.0.1   localhost\n127.0.1.1   NEW_HOSTNAME NEW_SHORT_NAME<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For <code>web03.example.com<\/code>, replace <code>NEW_SHORT_NAME<\/code> with <code>web03<\/code>. If you chose only <code>web03<\/code>, use <code>127.0.1.1 web03<\/code> instead. Keep one machine-name entry rather than leaving both the old and new names on separate <code>127.0.1.1<\/code> lines.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Save with <code>Ctrl+O<\/code>, press <code>Enter<\/code>, then exit with <code>Ctrl+X<\/code>. Test the resolver:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>getent hosts NEW_HOSTNAME\nhostname --fqdn\nhostname --short<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For the example FQDN, successful output resembles:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>127.0.1.1       web03.example.com web03\nweb03.example.com\nweb03<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Ubuntu&#8217;s <a href=\"https:\/\/ubuntu.com\/server\/docs\/explanation\/networking\/configuring-networks\/\" target=\"_blank\" rel=\"noopener\">networking documentation<\/a> uses <code>127.0.1.1<\/code> for a local machine name and explains that <code>\/etc\/hosts<\/code> entries normally take precedence over DNS. This mapping affects the VPS only; create an A or AAAA record separately when other machines must resolve the name.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Prevent a cloud-init reset when necessary<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Some VPS images use cloud-init to apply a provider-supplied hostname during boot, so check for it only if the name later changes back.<\/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 the hostname remains correct after a reboot, no change is needed. If it restores the old value, create a small drop-in that preserves the hostname you set locally:<\/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\">Replace <code>NEW_HOSTNAME<\/code> with the same value from Step 2. The <code>tee<\/code> 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\/yaml_examples\/update_hostname.html\" target=\"_blank\" rel=\"noopener\">cloud-init hostname documentation<\/a> documents this setting. If the provider still supplies a name from instance metadata, change that provisioning value too; otherwise it can compete with the local setting at the next boot.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Refresh the SSH session<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The kernel uses the new name immediately, but an existing shell prompt or application that cached the old value may not redraw it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostname\nhostnamectl --static\ncat \/etc\/hostname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">All three lines should contain your chosen name:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>web03.example.com\nweb03.example.com\nweb03.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Open a second SSH session to get a freshly generated prompt before closing the first one. Most services do not need a restart for this change; restart an individual application only if it reads the hostname once 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 real unit name for that application. Do not restart networking just to apply a hostname, 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 this final set to confirm the saved name, short form, FQDN lookup, and local address mapping:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostnamectl --static\nhostname --short\nhostname --fqdn\ngetent hosts NEW_HOSTNAME<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For <code>web03.example.com<\/code>, the first three lines should be the FQDN, <code>web03<\/code>, and the FQDN again. The final line should return the <code>127.0.1.1<\/code> entry or the expected DNS address. If these results agree, Ubuntu 26.04 is using the new hostname locally.<\/p>\n\n\n\n<aside class=\"vl-element vl-cta-banner\" aria-label=\"Set your server identity\">\n\t<div class=\"vl-cta-banner__content\">\n\t\t<p class=\"vl-cta-banner__eyebrow\">Ubuntu VPS<\/p>\n\t\t<h3 class=\"vl-cta-banner__title\">Set your server identity<\/h3>\n\t\t<p class=\"vl-cta-banner__text\">Deploy an Ubuntu 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 character Ubuntu rejects, usually a space, underscore, or trailing dot. Use lowercase letters, digits, hyphens, and dots in <code>NEW_HOSTNAME<\/code>; put spaces only in an optional pretty hostname. Check each FQDN label as well as the 64-character overall limit.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>hostname --fqdn<\/code> still shows the old name<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The static hostname changed, but <code>\/etc\/hosts<\/code> still has the previous <code>127.0.1.1<\/code> mapping or contains two competing machine-name lines. Edit the file, keep one line for the new name, and run the Step 3 checks again. If only remote computers see the old result, update public DNS rather than changing the local file again.<\/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, or image provisioning is applying a name during startup. Check <code>cloud-init status --long<\/code>, add the <code>99-preserve-hostname.cfg<\/code> drop-in from Step 4 when cloud-init is responsible, and update the provider&#8217;s hostname setting if metadata continues to overwrite it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>Failed to set hostname: Access denied<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The current account lacks permission to change the system name. Run the command with <code>sudo<\/code>, confirm that <code>sudo -v<\/code> succeeds, or reconnect as <code>root<\/code>; changing permissions on <code>\/etc\/hostname<\/code> is not a safe fix.<\/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 the public A or AAAA record and test it from another network if the name is used for a website, TLS, mail, or monitoring.<\/li>\n\n\n<li>Request a matching PTR record through the system that manages your VPS IP when reverse DNS matters.<\/li>\n\n\n<li>Update SSH inventory, backups, monitoring, certificates, and configuration management entries that still use the old hostname.<\/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 Ubuntu 26.04 after changing the hostname?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>hostnamectl<\/code> applies the static name immediately and stores it for the next boot. Reconnect over SSH to refresh the prompt, and restart only an application that caches the hostname during startup.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Can I use a short hostname without a domain?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Yes. A name such as <code>web03<\/code> is suitable for a standalone VPS or private network. Use an FQDN when TLS, mail, monitoring, or multi-server tools need a unique identity, and make sure it resolves through <code>\/etc\/hosts<\/code> or public DNS.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Does changing the hostname update DNS or reverse DNS?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. This procedure changes Ubuntu&#8217;s local system identity. Public forward DNS and reverse DNS are separate records managed by your DNS provider or the system that controls the VPS address.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is the difference between static and pretty hostnames?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The static hostname is the machine name saved in <code>\/etc\/hostname<\/code> and used by the operating system. A pretty hostname is an optional human-readable label that may contain spaces; it does not replace the static name used by services and boot configuration.<\/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 Ubuntu 26.04 after changing the hostname?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. `hostnamectl` applies the static name immediately and stores it for the next boot. Reconnect over SSH to refresh the prompt, and restart only an application that caches the hostname during startup.\"}}, {\"@type\": \"Question\", \"name\": \"Can I use a short hostname without a domain?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Yes. A name such as `web03` is suitable for a standalone VPS or private network. Use an FQDN when TLS, mail, monitoring, or multi-server tools need a unique identity, and make sure it resolves through `\/etc\/hosts` or public DNS.\"}}, {\"@type\": \"Question\", \"name\": \"Does changing the hostname update DNS or reverse DNS?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. This procedure changes Ubuntu's local system identity. Public forward DNS and reverse DNS are separate records managed by your DNS provider or the system that controls the VPS address.\"}}, {\"@type\": \"Question\", \"name\": \"What is the difference between static and pretty hostnames?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"The static hostname is the machine name saved in `\/etc\/hostname` and used by the operating system. A pretty hostname is an optional human-readable label that may contain spaces; it does not replace the static name used by services and boot configuration.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Change hostname on Ubuntu 26.04 with hostnamectl, update local name resolution, prevent cloud-init resets, and verify the new name without rebooting.","protected":false},"author":1,"featured_media":932,"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,104],"class_list":["post-931","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-hostname","tag-linux-vps","tag-ubuntu-26-04","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/931","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=931"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/931\/revisions"}],"predecessor-version":[{"id":3742,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/931\/revisions\/3742"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/932"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}