{"id":917,"date":"2026-10-24T18:00:00","date_gmt":"2026-10-24T18:00:00","guid":{"rendered":"https:\/\/vpslake.com\/blog\/?p=917"},"modified":"2026-10-24T18:00:00","modified_gmt":"2026-10-24T18:00:00","slug":"change-hostname-debian-13","status":"publish","type":"post","link":"https:\/\/vpslake.com\/blog\/2026\/10\/24\/change-hostname-debian-13\/","title":{"rendered":"How to Change Hostname on Debian 13 (Step-by-Step)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">To change hostname on Debian 13, set the persistent name with <code>hostnamectl<\/code> and update Debian&#8217;s local name mapping. The process takes about five minutes, applies without a reboot, and leaves you with checks that confirm both the operating system and resolver use the new name.<\/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 Debian GNU\/Linux 13 (Trixie).<\/li>\n\n\n<li>An SSH connection as <code>root<\/code>, or a normal user with working <code>sudo<\/code> privileges.<\/li>\n\n\n<li>A hostname made from lowercase letters, numbers, hyphens, and dots, such as <code>web02<\/code> or <code>web02.example.com<\/code>.<\/li>\n\n\n<li>The server&#8217;s IP address and access to your DNS provider if the name must resolve from other machines.<\/li>\n\n\n<li>A <a href=\"https:\/\/vpslake.com\/buy-vps\">VPSLake Linux VPS<\/a> if you need a Debian 13 server with root access.<\/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 current values before editing anything so you can tell a saved hostname from one supplied temporarily by DHCP or the VPS image.<\/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\ncat \/etc\/hostname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The release file should identify Debian 13 (Trixie). Empty static, transient, or pretty values are possible on a new VPS; they are not errors by themselves. A populated result may look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PRETTY_NAME=\"Debian GNU\/Linux 13 (trixie)\"\nold-web.example.com\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 value is the durable name. A transient value can come from network configuration, while a pretty hostname is an optional label intended for people rather than DNS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Set the Debian 13 static hostname<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use <code>hostnamectl<\/code> to update the running kernel and <code>\/etc\/hostname<\/code> together, which avoids leaving the active and next-boot names out of sync.<\/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>web02<\/code> or an FQDN such as <code>web02.example.com<\/code>. Do not include spaces, underscores, or a final dot. Debian 13&#8217;s <a href=\"https:\/\/manpages.debian.org\/trixie\/systemd\/hostnamectl.1.en.html\" target=\"_blank\" rel=\"noopener\"><code>hostnamectl<\/code> manual<\/a> describes static, transient, and pretty hostnames; static names are limited to DNS-style characters and a maximum of 64 characters.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The command normally has no success message. Both checks should print the new value:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>web02.example.com\nweb02.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If you also want a readable description, set it separately. This does not replace the static machine name:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo hostnamectl set-hostname \"Production web 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 web server<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Update Debian&#8217;s local name mapping<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Setting the hostname does not automatically make <code>hostname --fqdn<\/code> resolve to it. Debian commonly keeps the machine name on <code>127.0.1.1<\/code>, leaving <code>127.0.0.1<\/code> for <code>localhost<\/code>.<\/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 localhost and IPv6 entries. Replace the old machine-name line, or add one line like this for an FQDN:<\/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>web02.example.com<\/code>, <code>NEW_SHORT_NAME<\/code> is <code>web02<\/code>. If you chose only a short hostname, use <code>127.0.1.1 web02<\/code> instead. Keep a single <code>127.0.1.1<\/code> line for the machine; duplicate old and new entries can make lookups appear inconsistent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Save the file, then query the 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\">For the example FQDN, successful output is similar to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>127.0.1.1       web02.example.com web02\nweb02.example.com\nweb02<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This hosts-file entry changes name resolution on this VPS only. If other computers need the FQDN, create an A record for IPv4 or an AAAA record for IPv6 with your DNS provider. A local hostname change does not create public DNS or reverse DNS.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Check whether cloud-init manages the name<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Some VPS images run cloud-init at boot and can write a provider-supplied hostname after you change the local files. Check first; installing cloud-init is not necessary for this task.<\/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 name stays correct after a reboot, leave it alone. If it restores the old name, tell cloud-init to preserve the locally configured value:<\/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 provider continues applying a hostname 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\">The new name is active immediately, but an existing shell prompt may have been created with the old value. Confirm the active and persistent names, then open a second SSH session before closing the first one.<\/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 chosen hostname:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>web02.example.com\nweb02.example.com\nweb02.example.com<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Most applications do not need a restart just because the hostname changed. Restart an individual service only when 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. A reboot is optional and is not required to apply this change.<\/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 group after editing <code>\/etc\/hosts<\/code>. It checks the saved name, short form, fully qualified form, and the address returned by Debian&#8217;s 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>web02.example.com<\/code>, the first three lines should be the FQDN, <code>web02<\/code>, and the FQDN again. The last line should return the <code>127.0.1.1<\/code> mapping or the expected DNS address. You can also confirm that no stale local hostname remains:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>grep -nE '127\\\\.0\\\\.1\\\\.1|OLD_HOSTNAME|NEW_HOSTNAME' \/etc\/hosts<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace both uppercase placeholders before running the search. If the values agree, Debian 13 is using the new hostname locally.<\/p>\n\n\n\n<aside class=\"vl-element vl-cta-banner\" aria-label=\"Name your Debian server\">\n\t<div class=\"vl-cta-banner__content\">\n\t\t<p class=\"vl-cta-banner__eyebrow\">Debian VPS<\/p>\n\t\t<h3 class=\"vl-cta-banner__title\">Name your Debian server<\/h3>\n\t\t<p class=\"vl-cta-banner__text\">Deploy a Debian 13 VPS with root access for clean hostname and DNS configuration.<\/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, numbers, hyphens, and dots in <code>NEW_HOSTNAME<\/code>; put spaces only in the separate <code>--pretty<\/code> value. 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 persistent hostname changed, but <code>\/etc\/hosts<\/code> still has the previous <code>127.0.1.1<\/code> mapping or has two competing machine-name lines. Replace the stale entry, keep one mapping for the new name, and run <code>getent hosts NEW_HOSTNAME<\/code> again. If only remote computers see the old name, update public DNS and allow cached answers 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 boot. Check <code>cloud-init status --long<\/code>, add the <code>99-preserve-hostname.cfg<\/code> file from Step 4 if cloud-init is responsible, and update the provider&#8217;s hostname setting 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 does not have permission to change the system name. Run the command with <code>sudo<\/code>, verify that <code>sudo -v<\/code> succeeds, or reconnect as <code>root<\/code>; changing permissions on <code>\/etc\/hostname<\/code> is not a 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 the public A or AAAA record and test it from another network if the hostname is used for a website, mail, TLS, 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 records that still use 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 Debian 13 after changing the hostname?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No. <code>hostnamectl<\/code> changes the active name and writes <code>\/etc\/hostname<\/code> immediately. 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\">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>web02<\/code> is sufficient for a standalone VPS or private network. Choose 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. The command changes Debian&#8217;s local system identity only. Public forward DNS and reverse DNS are separate records managed by your DNS provider or VPS control panel.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why does Debian use <code>127.0.1.1<\/code> for the machine name?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Debian 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 server&#8217;s own name without depending on public DNS or binding it to a changing network address.<\/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 Debian 13 after changing the hostname?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"No. `hostnamectl` changes the active name and writes `\/etc\/hostname` immediately. Reconnect over SSH to refresh the prompt, and restart only an application that caches the hostname during startup.\"}}, {\"@type\": \"Question\", \"name\": \"Should I use a short hostname or an FQDN?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"A short name such as `web02` is sufficient for a standalone VPS or private network. Choose 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. The command changes Debian's local system identity only. Public forward DNS and reverse DNS are separate records managed by your DNS provider or VPS control panel.\"}}, {\"@type\": \"Question\", \"name\": \"Why does Debian use `127.0.1.1` for the machine name?\", \"acceptedAnswer\": {\"@type\": \"Answer\", \"text\": \"Debian commonly keeps `127.0.0.1` for `localhost` and uses `127.0.1.1` for the local machine name. That lets programs resolve the server's own name without depending on public DNS or binding it to a changing network address.\"}}]}<\/script>\n\n","protected":false},"excerpt":{"rendered":"Change hostname on Debian 13 with hostnamectl, update 127.0.1.1 in \/etc\/hosts, handle cloud-init, and verify the new name without rebooting.","protected":false},"author":1,"featured_media":918,"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":[98,106,93],"class_list":["post-917","post","type-post","status-publish","format-standard","has-post-thumbnail","category-guides","category-vps-hosting","tag-debian-13","tag-hostname","tag-linux-vps","cs-entry"],"_links":{"self":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/917","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=917"}],"version-history":[{"count":1,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/917\/revisions"}],"predecessor-version":[{"id":3719,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/posts\/917\/revisions\/3719"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media\/918"}],"wp:attachment":[{"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/media?parent=917"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/categories?post=917"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpslake.com\/blog\/wp-json\/wp\/v2\/tags?post=917"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}