{"id":4613,"date":"2019-02-07T11:56:07","date_gmt":"2019-02-07T13:56:07","guid":{"rendered":"https:\/\/blog.clusterweb.com.br\/?p=4613"},"modified":"2019-02-07T13:59:37","modified_gmt":"2019-02-07T15:59:37","slug":"como-alterar-o-hostname-no-ubuntu","status":"publish","type":"post","link":"https:\/\/blog.clusterweb.com.br\/?p=4613","title":{"rendered":"Como alterar o Hostname no Ubuntu"},"content":{"rendered":"<h3>Como posso mudar o hostname no Ubuntu ou Ubuntu Server usando a linha de comando?<\/h3>\n<p>Neste tutorial vamos mostrar um exemplo para modificar o nome do host (hostname) do seu ubuntu:<\/p>\n<p>Como ver o hostname atual do seu Ubuntu:<\/p>\n<blockquote><p>hostname<\/p><\/blockquote>\n<h3>Alterando o hostname temporariamente:<\/h3>\n<blockquote><p>hostname meu-novo-hostname<\/p><\/blockquote>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-233\" src=\"https:\/\/brasilcloud.com.br\/wp-content\/uploads\/2017\/11\/alterar-hostname-ubuntu.jpg\" sizes=\"auto, (max-width: 789px) 100vw, 789px\" srcset=\"https:\/\/brasilcloud.com.br\/wp-content\/uploads\/2017\/11\/alterar-hostname-ubuntu.jpg 789w, https:\/\/brasilcloud.com.br\/wp-content\/uploads\/2017\/11\/alterar-hostname-ubuntu-300x92.jpg 300w, https:\/\/brasilcloud.com.br\/wp-content\/uploads\/2017\/11\/alterar-hostname-ubuntu-768x237.jpg 768w\" alt=\"\" width=\"789\" height=\"243\" \/><\/p>\n<p><!--more--><\/p>\n<h3>Alterando o hostname permanentemente:<\/h3>\n<p><strong>1\u00aa Op\u00e7\u00e3o:<\/strong><\/p>\n<blockquote><p>hostnamectl set-hostname meu-novo-hostname<\/p><\/blockquote>\n<p>Verificando a altera\u00e7\u00e3o do hostname usando o comando:<\/p>\n<blockquote><p>hostnamectl status<\/p><\/blockquote>\n<p><strong>2\u00aa Op\u00e7\u00e3o:<\/strong><br \/>\nTamb\u00e9m e poss\u00edvel alterando o hostname no arquivo\u00a0<strong>\/etc\/hostname<\/strong>.<\/p>\n<p>First, let&#8217;s configure the hostname. If you issue the command hostname, you can see the hostname of your server (<strong>Figure A<\/strong>).<\/p>\n<p><strong>Figure A<\/strong><\/p>\n<figure class=\"image pull-none image-original\"><span class=\"img aspect-set \"><img decoding=\"async\" class=\"\" src=\"https:\/\/tr4.cbsistatic.com\/hub\/i\/2018\/06\/19\/761eeadf-4f58-4fa1-bac0-7208844f10bf\/hostnamea.jpg\" alt=\"Figure A\" \/><\/span><figcaption>\n<div class=\"caption\">\n<p>My Ubuntu Server 18.04 hostname.<\/p>\n<\/div>\n<\/figcaption><\/figure>\n<p>To change that hostname, open and edit the necessary file with the command\u00a0<em>sudo nano \/etc\/hostname<\/em>. Change the hostname to meet your needs and then save\/close the file.<\/p>\n<p>Next open the hosts file with the command\u00a0<em>sudo nano \/etc\/host<\/em>. Where you see your old hostname (i.e. localhost), change it to the new name. Save and close that file. Now, reboot your machine.<\/p>\n<p>That was a test.<\/p>\n<p>When the machine reboots, you should see your hostname has reverted to the original. Why is that? Because there&#8217;s a little setting, called\u00a0<em>preserve_hostname<\/em>, tucked away in a particular configuration file, that dictates to the platform to either preserve or not preserve the hostname as set in<em>\u00a0\/etc\/hostname<\/em>. To make that change, go back and alter your hostname (in both\u00a0<em>\/etc\/hostname<\/em>\u00a0and\u00a0<em>\/etc\/hosts<\/em>) and then issue the command:<\/p>\n<pre class=\"code\">sudo nano \/etc\/cloud\/cloud.cfg<\/pre>\n<p>In that file, look for the entry:<\/p>\n<pre class=\"code\">preserve_hostname: no<\/pre>\n<p>Change that entry to:<\/p>\n<pre class=\"code\">preserve_hostname: yes<\/pre>\n<p>Save and close that file. Now your newly configured hostname will remain, even after a reboot.<\/p>\n<h2>A small but frustrating change<\/h2>\n<p>Until you know about the preserve_hostname option, this change to the configuration of the Ubuntu Server hostname will certainly be one of frustration. I would suggest to Canonical, whenever such a change is made, it might behoove them to give some sort of indication in the standard configuration file. For example, in \/etc\/hostname it might have been smart to add this line:<\/p>\n<pre class=\"code\"># In order to preserve an altered hostname, set preserve_hostname to yes in\r\n# \/etc\/cloud\/cloud.cfg<\/pre>\n<p>Once the next LTS release comes out, that comment could be removed. It&#8217;d be a simple direction that would go a long way to prevent admins from growing frustrated with the implemented change.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Como posso mudar o hostname no Ubuntu ou Ubuntu Server usando a linha de comando? Neste tutorial vamos mostrar um exemplo para modificar o nome do host (hostname) do seu ubuntu: Como ver o hostname atual do seu Ubuntu: hostname Alterando o hostname temporariamente: hostname meu-novo-hostname<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[730,1,51,548],"tags":[1096,378,1084,361,698,273],"class_list":["post-4613","post","type-post","status-publish","format-standard","hentry","category-clusterweb","category-viazap","category-linux-linuxrs","category-ubuntu-2","tag-alterar","tag-como","tag-hostname","tag-no","tag-o","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/4613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4613"}],"version-history":[{"count":2,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/4613\/revisions"}],"predecessor-version":[{"id":4615,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/4613\/revisions\/4615"}],"wp:attachment":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4613"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4613"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}