{"id":5951,"date":"2016-06-13T16:49:46","date_gmt":"2016-06-13T16:49:46","guid":{"rendered":"http:\/\/ubuntuhandbook.org\/?p=5951"},"modified":"2016-06-13T16:49:46","modified_gmt":"2016-06-13T16:49:46","slug":"change-hostname-ubuntu-16-04-without-restart","status":"publish","type":"post","link":"https:\/\/ubuntuhandbook.org\/index.php\/2016\/06\/change-hostname-ubuntu-16-04-without-restart\/","title":{"rendered":"Change Hostname in Ubuntu 16.04 Without Restart"},"content":{"rendered":"<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/06\/ubuntu-logo-245.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/06\/ubuntu-logo-245.png\" alt=\"computer name ubuntu 16.04\" width=\"245\" height=\"250\" class=\"alignleft size-full wp-image-5952\" \/><\/a><\/p>\n<p>Quick tutorial for those who want to change the Hostname (Computer name) in Ubuntu 16.04 Server or Desktop without a restart.<\/p>\n<p><b>1. To change hostname temporarily<\/b> so it works until you reboot the machine:<\/p>\n<p>In terminal \/ command console, run the command:<\/p>\n<pre style=\"border:none;\">sudo hostname NEW_NAME_HERE<\/pre>\n<p><b>2. To permanently change your computer name<\/b>, you may edit the &#8220;\/etc\/hostname&#8221; and &#8220;\/etc\/hosts&#8221; files.<\/p>\n<p>Open terminal and run command:<\/p>\n<pre style=\"border:none;\">gksudo gedit \/etc\/hostname \/etc\/hosts<\/pre>\n<p>You may need to install gksu first via command <code>sudo apt install gksu<\/code>.<\/p>\n<p>For Ubuntu Server, use two <code>nano<\/code> commands instead (Press Ctrl+X, followed by Y, and then Enter to save changes):<\/p>\n<pre style=\"border:none;\">sudo nano \/etc\/hostname\nsudo nano \/etc\/hosts<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/06\/edit-hostname.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/06\/edit-hostname-600x140.jpg\" alt=\"edit-hostname\" width=\"600\" height=\"140\" class=\"aligncenter size-large wp-image-5953\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/06\/edit-hostname-600x140.jpg 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/06\/edit-hostname-450x105.jpg 450w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/06\/edit-hostname.jpg 1009w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>\n<p>When the files open, set the new hostname:<\/p>\n<ul>\n<li><b>\/etc\/hostname<\/b> is a simple one line file, change the name to whatever your want.<\/li>\n<li><b>\/etc\/hosts<\/b> maps IP addresses to host names, change the name in second line and make it SAME to the name in <b>\/etc\/hostname<\/b>.<\/li>\n<\/ul>\n<p>Without restarting your machine, just run the command below to restart hostname service to apply changes:<\/p>\n<pre style=\"border:none;\">systemctl restart systemd-logind.service<\/pre>\n<p><b>3.<\/b> There&#8217;s also <i>hostnamectl<\/i> command with <i>set-hostname<\/i> flag, which will alter the pretty, the static, and the transient hostname alike:<\/p>\n<pre style=\"border:none;\">hostnamectl set-hostname NEW_NAME_HERE<\/pre>\n<p><b>ISSUE:<\/b> After changing hostname, gedit and other graphical apps use X11\/Mir protocol  won&#8217;t launch from terminal via <code>gksudo<\/code>, you&#8217;ll get something like below:<\/p>\n<blockquote><p>Failed to connect to Mir: Failed to connect to server socket: No such file or directory<br \/>\nUnable to init server: Could not connect: Connection refused<\/p>\n<p>(gedit:20511): Gtk-WARNING **: cannot open display: :0<\/p><\/blockquote>\n<p>To fix it:<\/p>\n<p>run <code>xauth list<\/code> command to check authentication cookie.<br \/>\nadd a matching cookie for the new hostname:<\/p>\n<pre style=\"border:none;\">xauth add \"<span style=\"color:red;\">NEW_HOSTNAME<\/span>\/unix:0\" MIT-MAGIC-COOKIE-1 cookie-id-here<\/pre>\n<p><a href=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/06\/add-xauth.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/06\/add-xauth-600x59.jpg\" alt=\"add-xauth\" width=\"600\" height=\"59\" class=\"aligncenter size-large wp-image-5955\" srcset=\"https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/06\/add-xauth-600x59.jpg 600w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/06\/add-xauth-450x44.jpg 450w, https:\/\/ubuntuhandbook.org\/wp-content\/uploads\/2016\/06\/add-xauth.jpg 842w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Quick tutorial for those who want to change the Hostname (Computer name) in Ubuntu 16.04 Server or Desktop without a restart. 1. To change hostname temporarily so it works until you reboot the machine: In terminal \/ command console, run the command: sudo hostname NEW_NAME_HERE 2. To permanently change your computer name, you may edit [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[733,732],"class_list":["post-5951","post","type-post","status-publish","format-standard","hentry","category-howtos","tag-computer-name","tag-hostname"],"_links":{"self":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/5951","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/comments?post=5951"}],"version-history":[{"count":0,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/posts\/5951\/revisions"}],"wp:attachment":[{"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/media?parent=5951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/categories?post=5951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubuntuhandbook.org\/index.php\/wp-json\/wp\/v2\/tags?post=5951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}