{"id":5529,"date":"2023-11-27T11:27:58","date_gmt":"2023-11-27T11:27:58","guid":{"rendered":"https:\/\/natsav.com\/blog\/?p=5529"},"modified":"2024-02-01T12:22:35","modified_gmt":"2024-02-01T12:22:35","slug":"change-hostname-in-ubuntu","status":"publish","type":"post","link":"https:\/\/natsav.com\/blog\/change-hostname-in-ubuntu\/","title":{"rendered":"A Step-by-Step Guide on How to Change the Hostname in Ubuntu"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_68_1 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/natsav.com\/blog\/change-hostname-in-ubuntu\/#Step_1_Check_the_Current_Hostname\" title=\"Step 1: Check the Current Hostname\">Step 1: Check the Current Hostname<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/natsav.com\/blog\/change-hostname-in-ubuntu\/#Step_2_Edit_the_Hostname_File\" title=\"Step 2: Edit the Hostname File\">Step 2: Edit the Hostname File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/natsav.com\/blog\/change-hostname-in-ubuntu\/#Step_3_Edit_the_Hosts_File\" title=\"Step 3: Edit the Hosts File\">Step 3: Edit the Hosts File<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/natsav.com\/blog\/change-hostname-in-ubuntu\/#Step_4_Apply_the_Changes\" title=\"Step 4: Apply the Changes\">Step 4: Apply the Changes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/natsav.com\/blog\/change-hostname-in-ubuntu\/#Step_5_Verify_the_Changes\" title=\"Step 5: Verify the Changes\">Step 5: Verify the Changes<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Step_1_Check_the_Current_Hostname\"><\/span>Step 1: Check the Current Hostname<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before making any changes, it&#8217;s a good idea to check the current hostname. You can do this by entering the following command in the terminal:<\/p>\n<div class=\"bg-black rounded-md\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-bash\">#hostname<br \/>\n<\/code><\/div>\n<\/div>\n<p>This will display the current hostname of your system.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_2_Edit_the_Hostname_File\"><\/span>Step 2: Edit the Hostname File<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Next, open the <code>\/etc\/hostname<\/code> file using a text editor of your choice. For example, you can use <code>nano<\/code>:<\/p>\n<div class=\"bg-black rounded-md\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-bash\">#sudo nano \/etc\/hostname<br \/>\n<\/code><\/div>\n<\/div>\n<p>Replace the existing hostname with the new one, save the file, and exit the text editor.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_3_Edit_the_Hosts_File\"><\/span>Step 3: Edit the Hosts File<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now, open the <code>\/etc\/hosts<\/code> file:<\/p>\n<div class=\"bg-black rounded-md\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-bash\">#sudo nano \/etc\/hosts<br \/>\n<\/code><\/div>\n<\/div>\n<p>Locate the line with the old hostname and replace it with the new one. Save the file and exit.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_4_Apply_the_Changes\"><\/span>Step 4: Apply the Changes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>After editing the hostname and hosts files, apply the changes without restarting your system. Run the following command:<\/p>\n<div class=\"bg-black rounded-md\">\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-bash\">#sudo service hostname restart<br \/>\n<\/code><\/div>\n<\/div>\n<p>Alternatively, you can reboot your system to ensure the changes take effect.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_5_Verify_the_Changes\"><\/span>Step 5: Verify the Changes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Confirm that the new hostname is in place by running:<\/p>\n<div class=\"bg-black rounded-md\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 gizmo:dark:bg-token-surface-primary px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-bash\"># hostname<br \/>\n<\/code><\/div>\n<\/div>\n<p>Additionally, check the <code>\/etc\/hostname<\/code> and <code>\/etc\/hosts<\/code> files to ensure the changes are reflected.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Step 1: Check the Current Hostname Before making any changes, it&#8217;s a good idea to check the current hostname. You can do this by entering the following command in the terminal: #hostname This will display the current hostname of your system. Step 2: Edit the Hostname File Next, open the \/etc\/hostname file using a text [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5530,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[255],"tags":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/i0.wp.com\/natsav.com\/blog\/wp-content\/uploads\/2023\/11\/ubuntu-hostname.png?fit=507%2C289&ssl=1","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5529"}],"collection":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/comments?post=5529"}],"version-history":[{"count":6,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5529\/revisions"}],"predecessor-version":[{"id":5853,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/posts\/5529\/revisions\/5853"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media\/5530"}],"wp:attachment":[{"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/media?parent=5529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/categories?post=5529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/natsav.com\/blog\/wp-json\/wp\/v2\/tags?post=5529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}