{"id":18217,"date":"2024-01-28T12:45:50","date_gmt":"2024-01-28T09:45:50","guid":{"rendered":"https:\/\/infinitydomainhosting.com\/kb\/?p=18217"},"modified":"2025-09-24T19:10:22","modified_gmt":"2025-09-24T16:10:22","slug":"change-hostname-in-ubuntu","status":"publish","type":"post","link":"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-in-ubuntu\/","title":{"rendered":"Change hostname in Ubuntu"},"content":{"rendered":"\n<div>\n<div>\n<div>\n<div>\n<div>\n<div>\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 ' ><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-in-ubuntu\/#Change_Hostname_in_Ubuntu_A_Step-by-Step_Guide\" >Change Hostname in Ubuntu: A Step-by-Step Guide<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-in-ubuntu\/#What_is_a_Hostname\" >What is a 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-in-ubuntu\/#Why_would_you_want_to_change_your_hostname\" >Why would you want to change your hostname?<\/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-in-ubuntu\/#How_to_change_the_hostname_in_Ubuntu\" >How to change the hostname in Ubuntu?<\/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-in-ubuntu\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-in-ubuntu\/#Change_Hostname_in_Ubuntu\" >Change Hostname in Ubuntu<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-in-ubuntu\/#Change_Hostname_in_Ubuntu_A_Step-by-Step_Guide-2\" >Change Hostname in Ubuntu: A Step-by-Step Guide<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-in-ubuntu\/#What_is_a_Hostname-2\" >What is a Hostname?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-in-ubuntu\/#Why_would_you_want_to_change_your_hostname-2\" >Why would you want to change your hostname?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-in-ubuntu\/#How_to_change_the_hostname_in_Ubuntu-2\" >How to change the hostname in Ubuntu?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/infinitydomainhosting.com\/kb\/change-hostname-in-ubuntu\/#Frequently_Asked_Questions-2\" >Frequently Asked Questions<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Change_Hostname_in_Ubuntu_A_Step-by-Step_Guide\"><\/span>Change Hostname in Ubuntu: A Step-by-Step Guide<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Changing the <a href=\"https:\/\/hostadvice.com\/blog\/domains\/difference-between-hostname-and-domain-name\/\" target=\"_new\" rel=\"noopener\">hostname<\/a> in <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> relatively simple process, but it\u2019s important to understand why you might want to change your hostname and what steps you need to take to do so. In this article, we\u2019ll provide a detailed guide on how to change the hostname in Ubuntu, as well as answer some common questions about this process.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_is_a_Hostname\"><\/span>What is a Hostname?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A hostname is a label that is assigned to a device on a network. It is used to identify the device and distinguish it from other devices on the network. In the context of Ubuntu, the hostname is the <a href=\"https:\/\/www.hostinger.com\/domain-name-search\" target=\"_new\" rel=\"noopener\">name<\/a> that is given to the computer, and it is used to identify the computer on the network.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Why_would_you_want_to_change_your_hostname\"><\/span>Why would you want to change your hostname?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>There are several reasons why you might want to change the hostname of your Ubuntu machine. For example, if you are setting up a new server or virtual machine, you might want to give it a more descriptive or meaningful hostname that reflects its purpose or function. Or, if you are re-purposing a computer for a different use, you might want to change its hostname to reflect its new role.<\/p>\n<p>Additionally, changing the hostname can be useful for security reasons. A unique hostname can make it easier to identify a specific machine on the network, which can be helpful for monitoring and troubleshooting purposes.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_change_the_hostname_in_Ubuntu\"><\/span>How to change the hostname in Ubuntu?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li>Open a terminal window. You can do this by pressing Ctrl+Alt+T, or by searching for \u201cTerminal\u201d in the Ubuntu Dash.<\/li>\n<li>In the terminal window, type the following command to open the hostname file in a text editor: sudo nano \/etc\/hostname<\/li>\n<li>In the text editor, you will see the current hostname of your computer. Simply replace it with the new hostname that you want to use, and then save and close the file.<\/li>\n<li>Next, you will need to update <a href=\"https:\/\/www.hostinger.com\/tutorials\/how-to-edit-hosts-file\" target=\"_new\" rel=\"noopener\">the hosts<\/a> file. Type the following command in the terminal to open the hosts file: sudo nano \/etc\/hosts<\/li>\n<li>In the hosts file, you will see a line that looks like this: 127.0.0.1 localhost<br \/>\n                                    <br \/>You will need to add your new hostname to this line, so that it looks like this: 127.0.0.1 localhost your-new-hostname<\/li>\n<li>Save and close the hosts file.<\/li>\n<li>Finally, you will need to restart your computer to allow the changes to take effect. You can do this by typing the following command in the terminal: sudo reboot<\/li>\n<\/ol>\n<p>After following these steps, your Ubuntu machine will have a new hostname.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span><a href=\"https:\/\/www.a2hosting.com\/blog\/create-an-faq-page\/\" target=\"_new\" rel=\"noopener\">Frequently Asked Questions<\/a><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>                            <strong>Q: Do I need to be root to change the hostname?<\/strong> <br \/> A: Yes, you will need to use sudo to change the hostname, as the hostname file is located in a system directory that requires root privileges to modify.<\/p>\n<p>                            <strong>Q: Can I use special characters in the hostname?<\/strong><br \/> A: It is best to avoid using special characters in the hostname, as it can cause issues with some network services. Stick to using letters, numbers, and hyphens in your hostname.<\/p>\n<p>                            <strong>Q: Do I need to update any other configuration files after changing the hostname?<\/strong> <br \/> A: In most cases, updating the hostname and hosts files as described above will be sufficient to change the hostname. However, if you are using certain network services or applications, you may need to update their configuration files to ensure that they recognize the new hostname.<\/p>\n<p>In conclusion, changing the hostname in Ubuntu is a straightforward process that can be useful for a variety of reasons. Whether you are setting up a new machine or re-purposing an existing one, having the ability to change the hostname can be a valuable tool. By following the steps outlined in this article, you can easily change the hostname of your Ubuntu machine and customize <a href=\"https:\/\/support.hostinger.com\/en\/articles\/1863967-how-to-point-a-domain-to-hostinger\" target=\"_new\" rel=\"noopener\">it to<\/a> suit your needs.<\/p>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<p><\/body><\/p>\n<p><\/html><br \/>\n&#8220;`html<br \/>\n<!DOCTYPE html><br \/>\n<html lang=\"en\"><\/p>\n<p><head><br \/>\n    <meta charset=\"UTF-8\"><br \/>\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"><br \/>\n    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><br \/>\n    <title>Change Hostname in Ubuntu<\/title><br \/>\n<\/head><\/p>\n<p><body><\/p>\n<h1><span class=\"ez-toc-section\" id=\"Change_Hostname_in_Ubuntu\"><\/span>Change Hostname in Ubuntu<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<div>\n<div>\n<div>\n<div>\n<div>\n<div>\n<h2><span class=\"ez-toc-section\" id=\"Change_Hostname_in_Ubuntu_A_Step-by-Step_Guide-2\"><\/span>Change Hostname in Ubuntu: A Step-by-Step Guide<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Changing the <a href=\"https:\/\/hostadvice.com\/blog\/domains\/difference-between-hostname-and-domain-name\/\" target=\"_new\" rel=\"noopener\">hostname<\/a> in <a href=\"https:\/\/www.hostinger.com\/tutorials\/what-is-ubuntu\" target=\"_new\" rel=\"noopener\">Ubuntu<\/a> is a relatively simple process, but it\u2019s important to understand why you might want to change your hostname and what steps you need to take to do so. In this article, we\u2019ll provide a detailed guide on how to change the hostname in Ubuntu, as well as answer some common questions about this process.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_is_a_Hostname-2\"><\/span>What is a Hostname?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A hostname is a label that is assigned to a device on a network. It is used to identify the device and distinguish it from other devices on the network. In the context of Ubuntu, the hostname is the <a href=\"https:\/\/www.hostinger.com\/domain-name-search\" target=\"_new\" rel=\"noopener\">name<\/a> that is given to the computer, and it is used to identify the computer on the network.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Why_would_you_want_to_change_your_hostname-2\"><\/span>Why would you want to change your hostname?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>There are several reasons why you might want to change the hostname of your Ubuntu machine. For example, if you are setting up a new server or virtual machine, you might want to give it a more descriptive or meaningful hostname that reflects its purpose or function. Or, if you are re-purposing a computer for a different use, you might want to change its hostname to reflect its new role.<\/p>\n<p>Additionally, changing the hostname can be useful for security reasons. A unique hostname can make it easier to identify a specific machine on the network, which can be helpful for monitoring and troubleshooting purposes.<\/p>\n<p><!--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 in 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<h2><span class=\"ez-toc-section\" id=\"How_to_change_the_hostname_in_Ubuntu-2\"><\/span>How to change the hostname in Ubuntu?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ol>\n<li>Open a terminal window. You can do this by pressing Ctrl+Alt+T, or by searching for \u201cTerminal\u201d in the Ubuntu Dash.<\/li>\n<li>In the terminal window, type the following command to open the hostname file in a text editor: sudo nano \/etc\/hostname<\/li>\n<li>In the text editor, you will see the current hostname of your computer. Simply replace it with the new hostname that you want to use, and then save and close the file.<\/li>\n<li>Next, you will need to update <a href=\"https:\/\/www.hostinger.com\/tutorials\/how-to-edit-hosts-file\" target=\"_new\" rel=\"noopener\">the hosts<\/a> file. Type the following command in the terminal to open the hosts file: sudo nano \/etc\/hosts<\/li>\n<li>In the hosts file, you will see a line that looks like this: 127.0.0.1 localhost<br \/>\n                                    <br \/>You will need to add your new hostname to this line, so that it looks like this: 127.0.0.1 localhost your-new-hostname<\/li>\n<li>Save and close the hosts file.<\/li>\n<li>Finally, you will need to restart your computer to allow the changes to take effect. You can do this by typing the following command in the terminal: sudo reboot<\/li>\n<\/ol>\n<p>After following these steps, your Ubuntu machine will have a new hostname.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions-2\"><\/span><a href=\"https:\/\/www.a2hosting.com\/blog\/create-an-faq-page\/\" target=\"_new\" rel=\"noopener\">Frequently Asked Questions<\/a><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>                            <strong>Q: Do I need to be root to change the hostname?<\/strong> <\/p>\n<p>A: Yes, you will need to use sudo to change the hostname, as the hostname file is located in a system directory that requires root privileges to modify.<\/p>\n<p>                            <strong>Q: Can I use special characters in the hostname?<\/strong> <\/p>\n<p>A: It is best to avoid using special characters in the hostname, as it can cause issues with some network services. Stick to using letters, numbers, and hyphens in your hostname.<\/p>\n<p>                            <strong>Q: Do I need to update any other configuration files after changing the hostname?<\/strong> <\/p>\n<p>A: In most cases, updating the hostname and hosts files as described above will be sufficient to change the hostname. However, if you are using certain network services or applications, you may need to update their configuration files to ensure that they recognize the new hostname.<\/p>\n<p>In conclusion, changing the hostname in Ubuntu is a straightforward process that can be useful for a variety of reasons. Whether you are setting up a new machine or re-purposing an existing one, having the ability to change the hostname can be a valuable tool. By following the steps outlined in this article, you can easily change the hostname of your Ubuntu machine and customize <a href=\"https:\/\/support.hostinger.com\/en\/articles\/1863967-how-to-point-a-domain-to-hostinger\" target=\"_new\" rel=\"noopener\">it to<\/a> suit your needs.<\/p>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<p><\/body><\/p>\n<p><\/html><br \/>\n&#8220;`<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Change Hostname in Ubuntu: A Step-by-Step Guide Changing the hostname in Ubuntu is a relatively simple process, but it\u2019s important to understand&hellip;<\/p>\n","protected":false},"author":1,"featured_media":43763,"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-18217","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\/18217","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=18217"}],"version-history":[{"count":7,"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/posts\/18217\/revisions"}],"predecessor-version":[{"id":43764,"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/posts\/18217\/revisions\/43764"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/media\/43763"}],"wp:attachment":[{"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/media?parent=18217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/categories?post=18217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/infinitydomainhosting.com\/kb\/wp-json\/wp\/v2\/tags?post=18217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}