{"id":11355,"date":"2021-12-11T04:14:26","date_gmt":"2021-12-11T09:14:26","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=11355"},"modified":"2021-12-11T04:14:27","modified_gmt":"2021-12-11T09:14:27","slug":"permanently-change-hostname-in-ubuntu","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/","title":{"rendered":"How to Find and Permanently Change Hostname in Ubuntu Terminal"},"content":{"rendered":"\n

You do not need to do much to permanently change hostname in Ubuntu. To find out what your hostname is with the Ubuntu terminal. In Desktop environments you need to go to the Applications menu and click on Accessories \/ Terminal.<\/p>\n\n\n\n

When the terminal window opens you will be able to visually spot the hostname in two places. The first will be on the Title bar of the window while the other will be directly before the command-line prompt. In both cases, your hostname displays after your username in the format username@hostname<\/code>.<\/p>\n\n\n\n

If you want to unnecessarily drill down further, Ubuntu<\/a> like any other Linux<\/a> distro provides a command to print out the hostname. Simply type:<\/p>\n\n\n\n

$ hostname<\/p>\n\n\n\n

You can also display the current hostname with additional information by simply entering the following command:<\/p>\n\n\n\n

$ hostnamectl<\/code><\/pre>\n\n\n\n

You can change the hostname using hostnamectl<\/code> by running the following command:<\/p>\n\n\n\n

$ sudo hostnamectl set-hostname NewHostname<\/code><\/pre>\n\n\n\n

How to Permanently Change Hostname and Hosts Files<\/h2>\n\n\n\n

If you are using Ubuntu Desktop and its derivatives you can simply go to Settings (the gear icon) or About this Computer. If you had to open Settings, scroll down to where it says Details and click on that.<\/p>\n\n\n\n

Doing this should launch the About screen. Go to the editable text box labeled Device name. Type in the new hostname you would like into that field and press Enter to change it.<\/p>\n\n\n\n

Edit Hostname Using the Command-line<\/h2>\n\n\n\n

With the Terminal window open, type in the following command and enter:<\/p>\n\n\n\n

$ sudo hostname new-name<\/code><\/pre>\n\n\n\n

This command will change the hostname temporarily or until your restart your computer.<\/p>\n\n\n\n

To make the change permanent you will need to edit the hostname file. Open the hostname file using this command:<\/p>\n\n\n\n

$ sudo nano \/etc\/hostname<\/code><\/pre>\n\n\n\n

The file should contain nothing other than the hostname in the first line.<\/p>\n\n\n\n

One more step. You also need to change the hostname in one other place, the hosts file. Run the following command to open the hosts file:<\/p>\n\n\n\n

$ sudo nano \/etc\/hosts<\/code><\/pre>\n\n\n\n

With part of the output looking something like this after editing:<\/p>\n\n\n\n

127.0.0.1 localhost\n127.0.1.1 NewHostname<\/code><\/pre>\n\n\n\n

The \/etc\/hosts<\/code> resolve an IP address into a hostname.<\/p>\n\n\n\n

Go to the line with the old hostname and change it to the new one without altering any other part of the file then save and close the file. Once you change it in both of these locations, you can safely restart your computer and the new hostname will remain permanent.<\/p>\n\n\n\n

If your changes revert to the old hostname it could be because of cloud-init.<\/p>\n\n\n\n

About cloud-init<\/h2>\n\n\n\n

If you have the cloud-init package, a service used to initiate cloud services installed, you can also edit the \/etc\/cloud\/cloud.cfg<\/code> file. Your system may or may not have the \/etc\/cloud\/cloud.cfg<\/code> file. You can always confirm by entering:<\/p>\n\n\n\n

$ cd \/etc\/cloud<\/code><\/pre>\n\n\n\n

and then type ls to display the files in that location. If the file is there enter the command to edit the file:<\/p>\n\n\n\n

$ sudo nano \/etc\/cloud\/cloud.cfg<\/code><\/pre>\n\n\n\n

Find and set the parameter “preserve_hostname” from “false” to “true” then save.<\/p>\n\n\n\n

That’s it, you should now be able to permanently change hostname on your Ubuntu or any Linux system.<\/p>\n","protected":false},"excerpt":{"rendered":"

You do not need to do much to permanently change hostname in Ubuntu. To find out what your hostname is with the Ubuntu terminal. In Desktop environments you need to…<\/p>\n","protected":false},"author":1,"featured_media":11357,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,16],"tags":[183,193,354,424,433,544,573,591,598],"yoast_head":"\nHow to Find and Permanently Change Hostname in Ubuntu Terminal<\/title>\n<meta name=\"description\" content=\"In this guide, we will show you the best way to find and permanently change hostname in the Ubuntu Linux system command line terminal\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Find and Permanently Change Hostname in Ubuntu Terminal\" \/>\n<meta property=\"og:description\" content=\"In this guide, we will show you the best way to find and permanently change hostname in the Ubuntu Linux system command line terminal\" \/>\n<meta property=\"og:url\" content=\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/\" \/>\n<meta property=\"og:site_name\" content=\"Brightwhiz.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/brightwhiz\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-11T09:14:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-11T09:14:27+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/12\/permanently-change-hostname.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Michael Bright\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:site\" content=\"@brightwhizmag\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Michael Bright\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#article\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/\"},\"author\":{\"name\":\"Michael Bright\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\"},\"headline\":\"How to Find and Permanently Change Hostname in Ubuntu Terminal\",\"datePublished\":\"2021-12-11T09:14:26+00:00\",\"dateModified\":\"2021-12-11T09:14:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/\"},\"wordCount\":497,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/12\/permanently-change-hostname.jpg\",\"keywords\":[\"Debian\",\"DevOps\",\"Linux\",\"Open Source\",\"Optimization\",\"Software development\",\"Systems Administration\",\"Tools\",\"Ubuntu\"],\"articleSection\":[\"Articles\",\"Guides\",\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/\",\"url\":\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/\",\"name\":\"How to Find and Permanently Change Hostname in Ubuntu Terminal\",\"isPartOf\":{\"@id\":\"http:\/\/local.brightwhiz\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#primaryimage\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/12\/permanently-change-hostname.jpg\",\"datePublished\":\"2021-12-11T09:14:26+00:00\",\"dateModified\":\"2021-12-11T09:14:27+00:00\",\"description\":\"In this guide, we will show you the best way to find and permanently change hostname in the Ubuntu Linux system command line terminal\",\"breadcrumb\":{\"@id\":\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#primaryimage\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/12\/permanently-change-hostname.jpg\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/12\/permanently-change-hostname.jpg\",\"width\":1280,\"height\":680,\"caption\":\"Permanently Change Hostname\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/local.brightwhiz\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Find and Permanently Change Hostname in Ubuntu Terminal\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/local.brightwhiz\/#website\",\"url\":\"http:\/\/local.brightwhiz\/\",\"name\":\"Brightwhiz.com\",\"description\":\"Best Tech guides, Tutorials, and News\",\"publisher\":{\"@id\":\"http:\/\/local.brightwhiz\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/local.brightwhiz\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"http:\/\/local.brightwhiz\/#organization\",\"name\":\"Brightwhiz\",\"url\":\"http:\/\/local.brightwhiz\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"contentUrl\":\"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png\",\"width\":706,\"height\":135,\"caption\":\"Brightwhiz\"},\"image\":{\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/brightwhiz\/\",\"https:\/\/twitter.com\/brightwhizmag\",\"https:\/\/instagram.com\/bright_whiz\/\",\"https:\/\/www.pinterest.com\/sobbayi\/\",\"https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ\"]},{\"@type\":\"Person\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32\",\"name\":\"Michael Bright\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g\",\"caption\":\"Michael Bright\"},\"sameAs\":[\"https:\/\/sobbayi.com\"],\"url\":\"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Find and Permanently Change Hostname in Ubuntu Terminal","description":"In this guide, we will show you the best way to find and permanently change hostname in the Ubuntu Linux system command line terminal","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/","og_locale":"en_US","og_type":"article","og_title":"How to Find and Permanently Change Hostname in Ubuntu Terminal","og_description":"In this guide, we will show you the best way to find and permanently change hostname in the Ubuntu Linux system command line terminal","og_url":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/","og_site_name":"Brightwhiz.com","article_publisher":"https:\/\/www.facebook.com\/brightwhiz\/","article_published_time":"2021-12-11T09:14:26+00:00","article_modified_time":"2021-12-11T09:14:27+00:00","og_image":[{"width":1280,"height":680,"url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/12\/permanently-change-hostname.jpg","type":"image\/jpeg"}],"author":"Michael Bright","twitter_card":"summary_large_image","twitter_creator":"@brightwhizmag","twitter_site":"@brightwhizmag","twitter_misc":{"Written by":"Michael Bright","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#article","isPartOf":{"@id":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/"},"author":{"name":"Michael Bright","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32"},"headline":"How to Find and Permanently Change Hostname in Ubuntu Terminal","datePublished":"2021-12-11T09:14:26+00:00","dateModified":"2021-12-11T09:14:27+00:00","mainEntityOfPage":{"@id":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/"},"wordCount":497,"commentCount":0,"publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"image":{"@id":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/12\/permanently-change-hostname.jpg","keywords":["Debian","DevOps","Linux","Open Source","Optimization","Software development","Systems Administration","Tools","Ubuntu"],"articleSection":["Articles","Guides","Technology"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#respond"]}]},{"@type":"WebPage","@id":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/","url":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/","name":"How to Find and Permanently Change Hostname in Ubuntu Terminal","isPartOf":{"@id":"http:\/\/local.brightwhiz\/#website"},"primaryImageOfPage":{"@id":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#primaryimage"},"image":{"@id":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#primaryimage"},"thumbnailUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/12\/permanently-change-hostname.jpg","datePublished":"2021-12-11T09:14:26+00:00","dateModified":"2021-12-11T09:14:27+00:00","description":"In this guide, we will show you the best way to find and permanently change hostname in the Ubuntu Linux system command line terminal","breadcrumb":{"@id":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#primaryimage","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/12\/permanently-change-hostname.jpg","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/12\/permanently-change-hostname.jpg","width":1280,"height":680,"caption":"Permanently Change Hostname"},{"@type":"BreadcrumbList","@id":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/local.brightwhiz\/"},{"@type":"ListItem","position":2,"name":"How to Find and Permanently Change Hostname in Ubuntu Terminal"}]},{"@type":"WebSite","@id":"http:\/\/local.brightwhiz\/#website","url":"http:\/\/local.brightwhiz\/","name":"Brightwhiz.com","description":"Best Tech guides, Tutorials, and News","publisher":{"@id":"http:\/\/local.brightwhiz\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/local.brightwhiz\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"http:\/\/local.brightwhiz\/#organization","name":"Brightwhiz","url":"http:\/\/local.brightwhiz\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/","url":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","contentUrl":"http:\/\/local.brightwhiz\/wp-content\/uploads\/2021\/11\/brightwhiz-com-logo-orange.png","width":706,"height":135,"caption":"Brightwhiz"},"image":{"@id":"http:\/\/local.brightwhiz\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/brightwhiz\/","https:\/\/twitter.com\/brightwhizmag","https:\/\/instagram.com\/bright_whiz\/","https:\/\/www.pinterest.com\/sobbayi\/","https:\/\/www.youtube.com\/channel\/UC6sCdP_d_RiTIM7ErFT-PSQ"]},{"@type":"Person","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/81f0f3126f13834ae2e7f381b3028e32","name":"Michael Bright","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/local.brightwhiz\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/da90485875ff0aafa38fdd494abe87d1?s=96&d=mm&r=g","caption":"Michael Bright"},"sameAs":["https:\/\/sobbayi.com"],"url":"http:\/\/local.brightwhiz\/author\/sobbayiadmin\/"}]}},"_links":{"self":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/11355"}],"collection":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/comments?post=11355"}],"version-history":[{"count":0,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/posts\/11355\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media\/11357"}],"wp:attachment":[{"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/media?parent=11355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/categories?post=11355"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/local.brightwhiz\/wp-json\/wp\/v2\/tags?post=11355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}