{"id":927,"date":"2026-10-26T03:00:00","date_gmt":"2026-10-26T03:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=927"},"modified":"2026-10-26T03:00:00","modified_gmt":"2026-10-26T03:00:00","slug":"change-hostname-ubuntu-24-04","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/10\/26\/change-hostname-ubuntu-24-04\/","title":{"rendered":"How to Change Hostname on Ubuntu 24.04 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Change hostname on Ubuntu 24.04 with the built-in <code>hostnamectl<\/code> command, then make local name resolution agree with it. The change takes about five minutes, applies immediately, and does not normally 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>An Ubuntu Server 24.04 LTS VPS.<\/li>\n\n\n<li>An SSH connection as <code>root<\/code>, or a regular account with working <code>sudo<\/code> privileges.<\/li>\n\n\n<li>A terminal editor such as <code>nano<\/code>; no additional RAM or disk space is needed for a hostname change.<\/li>\n\n\n<li>A short name such as <code>app01<\/code>, or an FQDN such as <code>app01.example.com<\/code> made from lowercase letters, numbers, hyphens, and dots.<\/li>\n\n\n<li>Access to your DNS provider if other computers must resolve the FQDN. Local resolution works without a public domain.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> if you need an Ubuntu 24.04 server for this procedure.<\/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\">Why: recording the static, transient, and fully qualified values helps you spot a name supplied by cloud provisioning or DNS.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/os-release\nhostnamectl status --static\nhostnamectl status --transient\nhostnamectl status --pretty\nhostname\nhostname --fqdn<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The release file should identify Ubuntu 24.04. A blank static, transient, or pretty value is possible on a newly provisioned VPS and is not itself an error. A populated server might return output like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"Ubuntu 24.04 LTS\"\nold-app.example.com\nold-app.example.com\n\nold-app.example.com\nold-app.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The static hostname is the durable operating-system setting. A transient hostname can come from the network, while the pretty hostname is only a human-readable label.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Set the persistent Ubuntu hostname<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: <code>hostnamectl<\/code> changes the running system and the persistent hostname configuration through systemd in one operation.<\/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 name you selected, such as <code>app01<\/code> or <code>app01.example.com<\/code>. Do not use spaces, underscores, or a trailing dot. The <a href=\"https:\/\/www.freedesktop.org\/software\/systemd\/man\/latest\/hostnamectl.html\" target=\"_blank\" rel=\"noopener\">hostnamectl documentation<\/a> describes the static, transient, and pretty hostname types.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The set command normally prints nothing. The two checks should both show your new value:<\/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\">An optional pretty hostname can make administrative screens easier to read, but it does not replace the machine name used by services:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo hostnamectl set-hostname \"Production application server\" --pretty\nhostnamectl status --pretty<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Expected output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Production application server<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Align <code>\/etc\/hosts<\/code> with the new name<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: the hosts file gives Ubuntu a local answer for its own name before public DNS is available or has finished propagating.<\/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 entries. Replace the old machine-name line, or add one <code>127.0.1.1<\/code> entry. For an FQDN, use this pattern:<\/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>app01.example.com<\/code>, replace <code>NEW_HOSTNAME<\/code> with <code>app01.example.com<\/code> and <code>NEW_SHORT_NAME<\/code> with <code>app01<\/code>. If you chose only <code>app01<\/code>, use <code>127.0.1.1 app01<\/code> instead. Keep one current machine-name entry rather than leaving both the old and new lines in place.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Save the file, exit <code>nano<\/code>, and query Ubuntu&#8217;s resolver:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostname --fqdn\nhostname -s\ngetent hosts NEW_HOSTNAME<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For the FQDN example, successful output resembles:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app01.example.com\napp01\n127.0.1.1      app01.example.com app01<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This edit affects name lookups on the VPS only. Create an A record for IPv4 or an AAAA record for IPv6 with your DNS provider when the hostname must resolve from the internet. Forward DNS and reverse DNS are separate; request a matching PTR record through the system that manages your VPS address, such as the VPS control panel.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Prevent cloud-init from restoring the old name<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: Ubuntu cloud images may apply a provider-supplied hostname during boot, so check for cloud-init before deciding whether a persistence override is necessary.<\/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 stays correct after a reboot, no cloud-init change is needed. If cloud-init is installed and brings back the previous name, create a drop-in rather than editing the main configuration file:<\/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 <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\/modules.html\" target=\"_blank\" rel=\"noopener\">cloud-init module reference<\/a> documents <code>preserve_hostname<\/code>. If the provider still applies a name from instance metadata, update that provisioning value as well; otherwise it can overwrite the local setting on a later boot.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Refresh your SSH session<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Why: the kernel uses the new name immediately, but an existing shell prompt or application may have cached the old value when it started.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Confirm the active name and the file used at boot:<\/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>app01.example.com\napp01.example.com\napp01.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Open a second SSH session to get a fresh prompt before closing the first one. Most services do not need a restart for this change; restart only an application that 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 systemd unit name. Do not restart networking or reboot just to activate the hostname.<\/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 check after updating <code>\/etc\/hosts<\/code>. It tests the saved value, the short form, the FQDN result, and the address returned by the local name-service configuration.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostnamectl status --static\nhostname -s\nhostname --fqdn\ngetent hosts NEW_HOSTNAME<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For <code>app01.example.com<\/code>, the first three lines should be the FQDN, <code>app01<\/code>, and the FQDN again. The final line should return the <code>127.0.1.1<\/code> mapping or the expected DNS address. If you used only a short hostname, <code>hostname --fqdn<\/code> may return that short value when no domain is configured; that is normal.<\/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\">Ubuntu 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 Ubuntu 24.04 VPS with root access for straightforward 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 space, underscore, trailing dot, or unsupported punctuation. Use lowercase letters, numbers, hyphens, and dots in <code>NEW_HOSTNAME<\/code>; put spaces only in the optional pretty hostname. Also 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> still shows the old name<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The system hostname changed, but <code>\/etc\/hosts<\/code> still has the previous <code>127.0.1.1<\/code> mapping or contains duplicate machine-name lines. Replace the stale entry, keep one line for the new hostname, and run the verification commands again. If only another computer sees the old name, update public DNS and allow its cached result to expire.<\/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 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 change the provider&#8217;s provisioning hostname if it continues to overwrite the server.<\/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 the privilege required 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>Add and test the public A or AAAA record from another network if the name is used for a website, TLS, mail, or monitoring.<\/li>\n\n\n<li>Configure a matching PTR record in the VPS control panel when reverse DNS matters.<\/li>\n\n\n<li>Update SSH inventory, backups, monitoring, certificates, and configuration-management records that still identify the server by its 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 Ubuntu 24.04 after changing the hostname?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>hostnamectl<\/code> updates the active name and the persistent setting immediately. Start a new SSH session to refresh the prompt, and restart only an application that caches the name during startup.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Is an FQDN required for a VPS hostname?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. A short name such as <code>app01<\/code> is enough for a standalone server or private network. Choose an FQDN when TLS, mail, monitoring, or multi-server tooling needs a distinct DNS identity, and configure the corresponding local or public DNS record.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Will this change update forward DNS or reverse DNS?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. It changes Ubuntu&#8217;s local system identity. Public forward DNS is managed by your DNS provider, while reverse DNS is a separate PTR setting managed through the VPS provider or address owner.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why is <code>127.0.1.1<\/code> used in <code>\/etc\/hosts<\/code>?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Ubuntu commonly keeps <code>127.0.0.1<\/code> for <code>localhost<\/code> and uses <code>127.0.1.1<\/code> for the local machine name. That lets programs resolve the VPS&#8217;s own hostname without tying the local entry to an address that may change.<\/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 24.04 after changing the hostname?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. `hostnamectl` updates the active name and the persistent setting immediately. Start a new SSH session to refresh the prompt, and restart only an application that caches the name during startup.\"}}, {\"@type\": \"Question\", \"name\": \"Is an FQDN required for a VPS hostname?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. A short name such as `app01` is enough for a standalone server or private network. Choose an FQDN when TLS, mail, monitoring, or multi-server tooling needs a distinct DNS identity, and configure the corresponding local or public DNS record.\"}}, {\"@type\": \"Question\", \"name\": \"Will this change update forward DNS or reverse DNS?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. It changes Ubuntu's local system identity. Public forward DNS is managed by your DNS provider, while reverse DNS is a separate PTR setting managed through the VPS provider or address owner.\"}}, {\"@type\": \"Question\", \"name\": \"Why is `127.0.1.1` used in `\/etc\/hosts`?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Ubuntu commonly keeps `127.0.0.1` for `localhost` and uses `127.0.1.1` for the local machine name. That lets programs resolve the VPS's own hostname without tying the local entry to an address that may change.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Change hostname on Ubuntu 24.04 with hostnamectl, update local name resolution, prevent cloud-init resets, and verify the new name without a reboot.","protected":false},"author":1,"featured_media":928,"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,102],"class_list":["post-927","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-hostname","tag-linux-vps","tag-ubuntu-24-04","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/927","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=927"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/927\/revisions"}],"predecessor-version":[{"id":3737,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/927\/revisions\/3737"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/928"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}