{"id":18218,"date":"2024-01-27T19:53:54","date_gmt":"2024-01-27T16:53:54","guid":{"rendered":"https:\/\/infinitydomainhosting.com\/kb\/?p=18218"},"modified":"2025-09-24T19:10:22","modified_gmt":"2025-09-24T16:10:22","slug":"change-hostname-on-ubuntu","status":"publish","type":"post","link":"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-on-ubuntu\/","title":{"rendered":"Change hostname on Ubuntu"},"content":{"rendered":"<br \/>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">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-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-on-ubuntu\/#How_to_Change_Hostname_on_Ubuntu\" >How to Change Hostname on Ubuntu<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-on-ubuntu\/#Why_Change_the_Hostname\" >Why Change the Hostname?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-on-ubuntu\/#Steps_to_Change_Hostname_on_Ubuntu\" >Steps to Change Hostname on Ubuntu<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-on-ubuntu\/#FAQs\" >FAQs<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-on-ubuntu\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"How_to_Change_Hostname_on_Ubuntu\"><\/span>How to Change Hostname on Ubuntu<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<p><a href=\"https:\/\/www.hostinger.com\/tutorials\/what-is-ubuntu\" target=\"_new\" rel=\"noopener\">Ubuntu<\/a> is <a href=\"https:\/\/infinitydomainhosting.com\/kb\/the-ultimate-guide-to-amazon-web-hosting-everything-you-need-to-know\/\">a<\/a> popular <a href=\"https:\/\/www.hostinger.com\/tutorials\/linux-commands\" target=\"_new\" rel=\"noopener\">Linux<\/a> distribution known for its user-friendly interface and ease of use. Changing the <a href=\"https:\/\/hostadvice.com\/blog\/domains\/difference-between-hostname-and-domain-name\/\" target=\"_new\" rel=\"noopener\">hostname<\/a> on Ubuntu is a common task that users may need to perform, and it&#8217;s a straightforward process. This article will guide you through the steps to change the hostname.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Why_Change_the_Hostname\"><\/span>Why Change the Hostname?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>There are several reasons to change the hostname on your Ubuntu system:<\/p>\n<ul>\n<li>Setting up a new system or virtual machine and wanting to give it a more meaningful or descriptive <a href=\"https:\/\/www.hostinger.com\/domain-name-search\" target=\"_new\" rel=\"noopener\">name<\/a>.<\/li>\n<li>Working in a networked environment and needing to ensure each system has a unique and identifiable hostname.<\/li>\n<li>Troubleshooting network connectivity issues or errors related to the hostname.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Steps_to_Change_Hostname_on_Ubuntu\"><\/span>Steps to Change Hostname on Ubuntu<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To change the hostname on Ubuntu, follow these steps:<\/p>\n<p><strong>Step 1:<\/strong> Open a terminal window. You can do this by pressing Ctrl + Alt + T or by searching for Terminal in the applications menu.<\/p>\n<p><strong>Step 2:<\/strong> Once the terminal window is open, you will need to edit the <code>\/etc\/hostname<\/code> file. Use the following command:<\/p>\n<div class=\"dark bg-black rounded-md\">\n<div class=\"flex items-center relative text-token-text-secondary bg-token-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md\">sudo nano \/etc\/hostname<\/div>\n<div><\/div>\n<\/div>\n<p>This will open the <code>\/etc\/hostname<\/code> file in the Nano text editor.<\/p>\n<p><strong>Step 3:<\/strong> In the Nano text editor, locate the current hostname of your system. Use the arrow keys to navigate to this line, delete the old hostname, and type in the new hostname. After entering the new hostname, press Ctrl + X to exit Nano.<\/p>\n<p><strong>Step 4:<\/strong> When prompted to save the changes, press Y for yes, and then press Enter to confirm the filename.<\/p>\n<p><strong>Step 5:<\/strong> Next, you will need to edit the <code>\/etc\/hosts<\/code> file. Use the following command:<\/p>\n<div class=\"dark bg-black rounded-md\">\n<div class=\"flex items-center relative text-token-text-secondary bg-token-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md\">sudo nano \/etc\/hosts<\/div>\n<div><\/div>\n<\/div>\n<p><strong>Step 6:<\/strong> In the Nano text editor, locate a line that looks like this:<\/p>\n<div class=\"dark bg-black rounded-md\">\n<div class=\"flex items-center relative text-token-text-secondary bg-token-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md\">127.0.0.1 oldhostname<\/div>\n<div><\/div>\n<\/div>\n<p>Replace <code>oldhostname<\/code> with the new hostname. After making the change, press Ctrl + X to exit Nano.<\/p>\n<p><strong>Step 7:<\/strong> When prompted to save the changes, press Y for yes, and then press Enter to confirm the filename.<\/p>\n<p><strong>Step 8:<\/strong> To apply the new hostname, you will need to reboot your system. Use the following command:<\/p>\n<div class=\"dark bg-black rounded-md\">\n<div class=\"flex items-center relative text-token-text-secondary bg-token-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md\">sudo reboot<\/div>\n<div><\/div>\n<\/div>\n<p>After the system has rebooted, the new hostname will be applied. Verify the change by opening a terminal window and running the following command:<\/p>\n<div class=\"dark bg-black rounded-md\">\n<div class=\"flex items-center relative text-token-text-secondary bg-token-surface-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md\">hostname<\/div>\n<div><\/div>\n<\/div>\n<h2><span class=\"ez-toc-section\" id=\"FAQs\"><\/span>FAQs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><strong>Q: Do I need root privileges to change the hostname on Ubuntu?<\/strong> A: Yes, you will need root privileges to change the hostname on Ubuntu. Use the sudo command to run <a href=\"https:\/\/www.hostinger.com\/tutorials\/linux-commands\" target=\"_new\" rel=\"noopener\">commands<\/a> with root privileges.<\/p>\n<p><strong>Q: Can I change the hostname without restarting the system?<\/strong> A: No, you will need to reboot the system to apply the new hostname.<\/p>\n<p><strong>Q: Can I use special characters in the hostname?<\/strong> A: It is not recommended to use special characters in the hostname, as this can cause issues with network connectivity and may not be supported by all systems or applications.<\/p>\n<p><strong>Q: Will changing the hostname affect my network settings or configurations?<\/strong> A: Changing the hostname should not affect your network settings or configurations. However, it&#8217;s always a good idea to verify that the change was successful and that your network connectivity is working properly after changing the hostname.<\/p>\n<p><strong>Q: Can I revert back to the old hostname if I change my mind?<\/strong> A: Yes, you can revert back to the old hostname by following the same steps and using the original hostname in the <code>\/etc\/hostname<\/code> and <code>\/etc\/hosts<\/code> files.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>In summary, changing the hostname on Ubuntu is a simple and important task that can have significant benefits for system identification and network management. By following the steps outlined in this guide, you can easily change the hostname of your Ubuntu system. If you encounter any difficulties or have further questions, don&#8217;t hesitate to consult the FAQs section or seek help from the Ubuntu community.<\/p>\n<p><\/body><br \/>\n<\/html><br \/>\n<!--KB_CAT_BLOCK--><\/p>\n<figure class=\"kb-cat-placeholder\" style=\"margin:1.75rem 0;display:block;\"><img src=\"https:\/\/infinitydomainhosting.com\/kb\/assets\/img\/cat-general.webp\" alt=\"Change hostname on Ubuntu\" loading=\"lazy\" decoding=\"async\" style=\"max-width:100%;height:auto;display:block;border-radius:12px;box-shadow:0 8px 28px rgba(0,0,0,0.12);\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>How to Change Hostname on Ubuntu Ubuntu is a popular Linux distribution known for its user-friendly interface and ease of use. Changing&hellip;<\/p>\n","protected":false},"author":1,"featured_media":43765,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[1],"tags":[1833,831],"class_list":["post-18218","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-general","tag-hostname","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/posts\/18218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/comments?post=18218"}],"version-history":[{"count":6,"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/posts\/18218\/revisions"}],"predecessor-version":[{"id":43766,"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/posts\/18218\/revisions\/43766"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/media\/43765"}],"wp:attachment":[{"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/media?parent=18218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/categories?post=18218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/tags?post=18218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}