{"id":4317,"date":"2017-06-09T22:52:16","date_gmt":"2017-06-10T01:52:16","guid":{"rendered":"https:\/\/blog.clusterweb.com.br\/?p=4317"},"modified":"2017-06-09T22:53:54","modified_gmt":"2017-06-10T01:53:54","slug":"change-hostname-in-centos-7-rhel-7","status":"publish","type":"post","link":"https:\/\/blog.clusterweb.com.br\/?p=4317","title":{"rendered":"Change HostName in CentOS 7 \/ RHEL 7"},"content":{"rendered":"<p>After\u00a0installing the CentOS 7\u00a0on my server, i tried to change host name by modifying the \/etc\/sysconfig\/network; it did not take an effect of the modification. Even after multiple reboot of server, the host name remains localhost.localdomain. The procedure to change the host name in CentOS 7 is now totally different from the previous version, this guide will help you to setup the host name on CentOS 7 \/ RHEL 7.<\/p>\n<p><strong>CentOS 7 supports three class of Host Names:<\/strong><\/p>\n<p><strong>Static<\/strong>\u00a0\u2013 The static host name is traditional host which can be chosen by the user and is stored in \/etc\/hostname file.<\/p>\n<p><strong>Transient<\/strong>\u00a0\u2013 The transient host name is maintained by kernel and can be changed by DHCP and mDNS.<\/p>\n<p><strong>Pretty<\/strong>\u00a0\u2013 It is a free form UTF -8 host name for the presentation to the user.<\/p>\n<p><strong>HostName can be,<\/strong><\/p>\n<ul>\n<li>64 character in a length<\/li>\n<li>Recommend to have FQDN<\/li>\n<li>Consists of a-z,A-Z, 0-9, \u201c-\u201d, \u201c_\u201d and \u201c.\u201d only<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<p><strong>How to Change:<\/strong><\/p>\n<p>Before changing the host name, lets check the current host name.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@localhost ~]# hostname\r\nlocalhost.localdomain<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>1. nmtui tool:<\/strong><\/p>\n<p>NetworkManaget tool is used to set the static host name in \/etc\/hostname file.<\/p>\n<figure id=\"attachment_7134\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7134\" src=\"http:\/\/cdn.itzgeek.com\/wp-content\/uploads\/2014\/07\/nmtui-Change-HostName-1.jpg\" alt=\"nmtui -Select Set HostName \" width=\"216\" height=\"206\" \/><figcaption class=\"wp-caption-text\">nmtui -Select Set HostName<\/figcaption><\/figure>\n<p>Set the host name.<\/p>\n<figure id=\"attachment_7135\" class=\"wp-caption aligncenter\"><figcaption class=\"wp-caption-text\">nmtui \u2013 Change HostName 2<\/figcaption><\/figure>\n<p>restart the hostnamed to force the hostnamectl to notice the change in static host name.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@localhost ~]# systemctl restart systemd-hostnamed<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>You can verify the change in host name.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# hostname\r\nserver.itzgeek.com\r\n[root@server ~]# cat \/etc\/hostname\r\nserver.itzgeek.com\r\n[root@server ~]# cat \/etc\/sysconfig\/network\r\n# Created by anaconda\r\nHOSTNAME=server.itzgeek.com<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>2. hostnamectl:<\/strong><\/p>\n<p>hostnamectl is used to change the host name, with this tool we can change all the three class of host name; here we look only static host name.<\/p>\n<p>Check the current host name.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# hostnamectl status<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">Static hostname: server.itzgeek.com\r\nIcon name: computer-vm\r\nChassis: vm\r\nMachine ID: 565ea8b749544aca9d5563308f9e4bc2\r\nBoot ID: 5c979d9b5f754df8b75a4e3aeabf2bad\r\nVirtualization: vmware\r\nOperating System: CentOS Linux 7 (Core)\r\nCPE OS Name: cpe:\/o:centos:centos:7\r\nKernel: Linux 3.10.0-123.el7.x86_64\r\nArchitecture: x86_64<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Set the hostname.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@server ~]# hostnamectl set-hostname client.itzgeek.com<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Check the host name again (Close the session and open new session using putty or console)<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@client ~]# hostnamectl status<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">Static hostname: client.itzgeek.com\r\nIcon name: computer-vm\r\nChassis: vm\r\nMachine ID: 565ea8b749544aca9d5563308f9e4bc2\r\nBoot ID: 5c979d9b5f754df8b75a4e3aeabf2bad\r\nVirtualization: vmware\r\nOperating System: CentOS Linux 7 (Core)\r\nCPE OS Name: cpe:\/o:centos:centos:7\r\nKernel: Linux 3.10.0-123.el7.x86_64\r\nArchitecture: x86_64<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>If you use this command, you do not require to notify the change in host name. Close the current session and re launch the terminal.<\/p>\n<p><strong>3. nmcli tool:<\/strong><\/p>\n<p>It can be used to query and setup the static host name in \/etc\/hostname file.<\/p>\n<p>Check the hostname.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@client ~]# nmcli general hostname\r\nclient.itzgeek.com<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>Change the host name.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@client ~]# nmcli general hostname server.itzgeek.com<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>restart the hostnamed to force the hostnamectl to notice the change in static host name.<\/p>\n<div class=\"wp_syntax\">\n<table>\n<tbody>\n<tr>\n<td class=\"code\">\n<pre class=\"dos\">[root@client ~]# systemctl restart systemd-hostnamed<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>4. Edit \/etc\/hostname<\/strong><\/p>\n<p>This is the simple, but requires a reboot of server to take an effect.<\/p>\n<p><strong>Note:<\/strong>\u00a0<strong>Use the hostnamectl to change the host name, which fair better than other commands and does not require to update the kernel about the change in host name.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>After\u00a0installing the CentOS 7\u00a0on my server, i tried to change host name by modifying the \/etc\/sysconfig\/network; it did not take an effect of the modification. Even after multiple reboot of server, the host name remains localhost.localdomain. The procedure to change the host name in CentOS 7 is now totally different from the previous version, this [&hellip;]<\/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":[1082,730,1,42,51],"tags":[1085,1083,1084,1065,1086],"class_list":["post-4317","post","type-post","status-publish","format-standard","hentry","category-centos-7-rhel-7","category-clusterweb","category-viazap","category-leitura-recomendada","category-linux-linuxrs","tag-centos-7","tag-change","tag-hostname","tag-in","tag-rhel-7"],"_links":{"self":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/4317","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=4317"}],"version-history":[{"count":2,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/4317\/revisions"}],"predecessor-version":[{"id":4319,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/4317\/revisions\/4319"}],"wp:attachment":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}