{"id":223,"date":"2017-11-22T17:56:02","date_gmt":"2017-11-22T17:56:02","guid":{"rendered":"http:\/\/cheapwindowsvps.com\/blog\/?p=223"},"modified":"2025-01-23T10:53:41","modified_gmt":"2025-01-23T10:53:41","slug":"how-to-change-hostname-in-ubuntu-16-04","status":"publish","type":"post","link":"https:\/\/cheapwindowsvps.com\/blog\/how-to-change-hostname-in-ubuntu-16-04\/","title":{"rendered":"How to Change Hostname in Ubuntu 16.04"},"content":{"rendered":"<p>For those who pay attention to the little details, the default hostname in Ubuntu 16.04 can be a constant source of irritation. Something like &#8216;dell-laptop-3344&#8217; just won&#8217;t do for a hostname when you&#8217;re used to more sensible and exotic stuff. So, how do you get back control (and sanity)?<\/p>\n<p>Changing the hostname is one of the simplest things you can do in <a href=\"http:\/\/releases.ubuntu.com\/16.04\/\" target=\"_blank\" rel=\"noopener\">Ubuntu 16.04<\/a>. The hostname is simply looked up from a file called \/etc\/hosts, and in order to change it, you guessed it, we just need to change that file.<\/p>\n<p>With that in mind, go to the terminal and do this:<\/p>\n<blockquote><p>$ sudo gedit \/etc\/hosts<\/p><\/blockquote>\n<p>This command opens the \/etc\/hosts file in the default text editor (which is called Gedit in Ubuntu). We add &#8216;sudo&#8217; here because it&#8217;s a system-level file and is not in the reach of regular users for change.<\/p>\n<p>After you provide your root password, you&#8217;ll see the file having entries like these:<\/p>\n<blockquote><p>127.0.0.1\u00a0\u00a0\u00a0\u00a0\u00a0 localhost<\/p>\n<p>127.0.0.1\u00a0\u00a0\u00a0\u00a0\u00a0 dell-laptop-3344<\/p><\/blockquote>\n<p>See the culprit there? The name &#8216;dell-laptop-3344&#8217; is linked to the IP address 127.0.0.1, which is the same machine you&#8217;re working on. Just change this name to the one you want (how about &#8216;overlord&#8217;?!) and save it. Close this file, restart your system, and you&#8217;re good to go!<\/p>\n<p>A small aside, by the way: Notice the line &#8216;127.0.0.1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 localhost&#8217; in the file \/etc\/hosts? That maps the name &#8216;localhost&#8217; to the machine you&#8217;re on. That&#8217;s what allows you to type &#8216;http:\/\/localhost&#8217; and be able to visit the web server of the machine you&#8217;re on.<\/p>\n<h2><strong>Changing the Hostname in Ubuntu 16.04 Without Restarting<\/strong><\/h2>\n<p>Well, what if you don&#8217;t want to restart your system and yet change the hostname? Is there a command for that? There is, but unfortunately, it remains effective only in the current session. You can do:<\/p>\n<blockquote><p>$ sudo hostname overlord<\/p><\/blockquote>\n<p>to change your hostname to &#8216;overlord&#8217; instantly. And once you do the same in the \/etc\/hosts file, you&#8217;ll end up with the best of both worlds: your hostname will be changed instantly, and the new (same) hostname will be read from \/etc\/hosts the next time you start up.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For those who pay attention to the little details, the default hostname in Ubuntu 16.04 can be a constant source of irritation. Something like &#8216;dell-laptop-3344&#8217; just won&#8217;t do for a hostname when you&#8217;re used to more sensible and exotic stuff. So, how do you get back control (and sanity)? Changing the hostname is one of [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-223","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/223","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/comments?post=223"}],"version-history":[{"count":5,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/223\/revisions"}],"predecessor-version":[{"id":10518,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/223\/revisions\/10518"}],"wp:attachment":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media?parent=223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/categories?post=223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/tags?post=223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}