
{"id":30205,"date":"2026-04-07T13:27:12","date_gmt":"2026-04-07T11:27:12","guid":{"rendered":"https:\/\/contabo.com\/blog\/?p=30205"},"modified":"2026-04-24T13:33:23","modified_gmt":"2026-04-24T11:33:23","slug":"how-to-change-hostname-in-linux","status":"publish","type":"post","link":"https:\/\/contabo.com\/blog\/how-to-change-hostname-in-linux\/","title":{"rendered":"How to Change Hostname in Linux: Full Guide"},"content":{"rendered":"\n<p>Your server&#8217;s hostname is how it identifies itself on the network. Get it wrong and you&#8217;ll break mail delivery, SSL certificates, and any service that relies on reverse DNS. Here&#8217;s how to change it correctly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-a-linux-hostname\">What Is a Linux Hostname?<\/h2>\n\n\n\n<p>A hostname is a human-readable label assigned to a machine on a network. It maps to an IP address and gets used in everything from SSH prompts to system logs to SSL certificate validation.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-static-pretty-and-transient-hostnames\">Static, Pretty, and Transient Hostnames<\/h3>\n\n\n\n<p>Linux tracks three hostname types. The static hostname is the persistent one stored in \/etc\/hostname and loaded at boot. The pretty hostname is a free-form label that can include spaces and special characters, stored in \/etc\/machine-info. The transient hostname is a runtime value that can be set by DHCP or mDNS and overrides the static one temporarily.<\/p>\n\n\n\n<p>For server environments, the static hostname is the one that matters.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-how-to-check-your-current-hostname\">How to Check Your Current Hostname<\/h3>\n\n\n\n<p>Two commands cover this. For a quick one-liner:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostname<\/code><\/pre>\n\n\n\n<p>For full details including all three hostname types:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostnamectl<\/code><\/pre>\n\n\n\n<p>The hostnamectl output also shows virtualization type, OS, and kernel version, which makes it useful during initial server setup.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-change-hostname-permanently\">How to Change Hostname Permanently<\/h2>\n\n\n\n<p>Permanent hostname changes persist across reboots. You need this when setting up a new server, renaming a machine in your infrastructure, or fixing a hostname that was set incorrectly during provisioning.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-hostnamectl\">Using hostnamectl<\/h3>\n\n\n\n<p>On systemd-based distros (Ubuntu 16.04+, CentOS 7+, Debian 8+), hostnamectl is the cleanest option:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo hostnamectl set-hostname new-hostname<\/code><\/pre>\n\n\n\n<p>Replace new-hostname with your desired name. No reboot required. The change takes effect in new shell sessions. Verify it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>hostnamectl<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-editing-etc-hostname-directly\">Editing \/etc\/hostname Directly<\/h3>\n\n\n\n<p>You can also edit the hostname file manually:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/hostname<\/code><\/pre>\n\n\n\n<p>Replace the existing name with your new hostname, save, and reboot. Simple, but you lose the ability to set pretty or transient hostnames this way.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-nmtui-for-networkmanager-systems\">Using nmtui for NetworkManager Systems<\/h3>\n\n\n\n<p>On systems running NetworkManager, nmtui provides a menu-driven interface. Launch it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nmtui<\/code><\/pre>\n\n\n\n<p>Navigate to Set system hostname, enter your new name, and confirm. This method is particularly useful on desktop Linux installs or when you prefer avoiding the command line.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-to-change-hostname-temporarily\">How to Change Hostname Temporarily<\/h2>\n\n\n\n<p>Temporary hostname changes don&#8217;t survive a reboot. Useful for testing or short-lived environments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-hostname-command\">Using the hostname Command<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo hostname temp-hostname<\/code><\/pre>\n\n\n\n<p>This changes the transient hostname immediately. Check it with hostname. Once you reboot, the static hostname from \/etc\/hostname takes over again.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-updating-etc-hosts-after-a-hostname-change\">Updating \/etc\/hosts After a Hostname Change<\/h2>\n\n\n\n<p>Changing your hostname without updating \/etc\/hosts creates problems. Many local services resolve the hostname against \/etc\/hosts, and a mismatch causes slow DNS lookups and broken local network resolution.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-why-etc-hosts-must-match-your-hostname\">Why \/etc\/hosts Must Match Your Hostname<\/h3>\n\n\n\n<p>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>Find the line that maps 127.0.1.1 (or 127.0.0.1 on some distros) to your old hostname and update it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>127.0.1.1 \u00a0 new-hostname<\/code><\/pre>\n\n\n\n<p>Save and close. You don&#8217;t need a reboot for this change to take effect.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-common-hostname-naming-rules\">Common Hostname Naming Rules<\/h2>\n\n\n\n<p>Hostnames have strict formatting requirements. Ignore them and you&#8217;ll get subtle failures in certificate validation, DNS, and inter-service communication:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Maximum 253 characters total, with each label between dots limited to 63 characters.<\/li>\n\n\n\n<li>Only letters (a-z, A-Z), digits (0-9), and hyphens are allowed. No underscores, no spaces, no dots in the short hostname.<\/li>\n\n\n\n<li>Cannot start or end with a hyphen.<\/li>\n\n\n\n<li>Lowercase only is standard practice, even though the system accepts uppercase.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-faq-linux-change-hostname\">FAQ: Linux Change Hostname<\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777030167417\"><strong class=\"schema-faq-question\">How do I permanently change my hostname in Linux?<\/strong> <p class=\"schema-faq-answer\">Run: sudo hostnamectl set-hostname your-new-hostname. Then update \/etc\/hosts to match. The change persists across reboots without requiring one.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777030176949\"><strong class=\"schema-faq-question\">Does changing hostname require a reboot?<\/strong> <p class=\"schema-faq-answer\">Not when using hostnamectl. The new hostname takes effect immediately in new shell sessions. Existing sessions still show the old hostname until you open a new terminal or re-login.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777030188409\"><strong class=\"schema-faq-question\">What command shows the current hostname?<\/strong> <p class=\"schema-faq-answer\">Run hostname for a quick check, or hostnamectl for full details including static, pretty, and transient values.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1777030196970\"><strong class=\"schema-faq-question\">How do I change hostname in Ubuntu?<\/strong> <p class=\"schema-faq-answer\">Use sudo hostnamectl set-hostname new-name on Ubuntu 16.04 and later. Then edit \/etc\/hosts to update the 127.0.1.1 entry. No reboot required.<\/p> <\/div> <\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Your server&#8217;s hostname is how it identifies itself on the network. Get it wrong and you&#8217;ll break mail delivery, SSL certificates, and any service that relies on reverse DNS. Here&#8217;s how to change it correctly. What Is a Linux Hostname? A hostname is a human-readable label assigned to a machine on a network. It maps [&hellip;]<\/p>\n","protected":false},"author":77,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[18],"tags":[],"ppma_author":[3116],"class_list":["post-30205","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Anika Kopte","author_link":"https:\/\/contabo.com\/blog\/author\/anika\/"},"uagb_comment_info":0,"uagb_excerpt":"Your server&#8217;s hostname is how it identifies itself on the network. Get it wrong and you&#8217;ll break mail delivery, SSL certificates, and any service that relies on reverse DNS. Here&#8217;s how to change it correctly. What Is a Linux Hostname? A hostname is a human-readable label assigned to a machine on a network. It maps&hellip;","authors":[{"term_id":3116,"user_id":77,"is_guest":0,"slug":"anika","display_name":"Anika Kopte","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/1c425caa652c679ae47e3f85a48de4e19f09d37bcb5593ba88a7aa4a08bb1d81?s=96&d=mm&r=g","0":null,"1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":""}],"_links":{"self":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/30205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/comments?post=30205"}],"version-history":[{"count":1,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/30205\/revisions"}],"predecessor-version":[{"id":30206,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/posts\/30205\/revisions\/30206"}],"wp:attachment":[{"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/media?parent=30205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/categories?post=30205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/tags?post=30205"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/contabo.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=30205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}