{"id":159,"date":"2021-03-22T09:32:45","date_gmt":"2021-03-22T09:32:45","guid":{"rendered":"http:\/\/blog.successionua.com\/?p=159"},"modified":"2021-03-22T09:32:45","modified_gmt":"2021-03-22T09:32:45","slug":"changing-hostname-on-rhel","status":"publish","type":"post","link":"https:\/\/geckich.space\/?p=159","title":{"rendered":"Changing hostname on RHEL"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left;\">\n<h2>For RHEL 6:<\/h2>\n<p>1. Change the <span style=\"font-family: monospace;\">HOSTNAME<\/span>\u00a0line in\u00a0<span style=\"font-family: monospace;\">\/etc\/sysconfig\/network<\/span><\/p>\n<p>2. Change the hostname (FQDN and alias) in\u00a0<span style=\"font-family: monospace;\">\/etc\/hosts<\/span><\/p>\n<p>3. Run\u00a0<span style=\"font-family: monospace; font-weight: bold;\">\/bin\/hostname new_hostname<\/span>\u00a0for the hostname change to take effect immediately.<\/p>\n<p>4. Run\u00a0<span style=\"font-family: monospace; font-weight: bold;\">\/sbin\/service syslog restart<\/span>\u00a0for\u00a0<span style=\"font-family: monospace;\">syslog<\/span>\u00a0to log using the new hostname.<\/p>\n<p>A reboot is not required to change the system hostname.<\/p>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">For RHEL 7:<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Method 1 : hostnamectl<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Get the current hostname of the system :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">hostnamectl status<\/pre>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<pre class=\"wp-block-preformatted\"><code>Static hostname: localhost.localdomain<br>Icon name: computer<br>Chassis: n\/a<br>Machine ID: 55cc1c57c7f24ed0b0d352648024cea6<br>Boot ID: a12ec8e04e6b4534841d14dc8425e38c<br>Virtualization: vmware<br>Operating System: CentOS Linux 7 (Core)<br>CPE OS Name: cpe:\/o:centos:centos:7<br>Kernel: Linux 3.10.0-123.el7.x86_64<br>Architecture: x86_64<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To set new hostname (butterfly) for the machine :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">hostnamectl set-hostname butterfly<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Re-login and verify the new hostname :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">hostnamectl<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">Static hostname: butterfly\nPretty hostname: Geeks LAB\nIcon name: computer\nChassis: n\/a\nMachine ID: 55cc1c57c7f24ed0b0d352648024cea6\nBoot ID: a12ec8e04e6b4534841d14dc8425e38c\nVirtualization: vmware\nOperating System: CentOS Linux 7 (Core)\nCPE OS Name: cpe:\/o:centos:centos:7\nKernel: Linux 3.10.0-123.el7.x86_64\nArchitecture: x86_64<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Method 2 : nmcli<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Get the current hostname :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nmcli general hostname<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">localhost.localdomain<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To change the hostname to butterfly :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nmcli general hostname butterfly<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We need to restart the systemd-hostnamed service for the changes to take effect :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">service systemd-hostnamed restart<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Re-login and verify the hostname change :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">hostname<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">butterfly<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Method 3 : nmtui<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We can also change the hostname using the nmtui tool :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">nmtui<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Select the option to \u201cset the hostname\u201d and hit enter<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/cdn.thegeekdiary.com\/wp-content\/uploads\/2015\/09\/change-hostname-nmtui.png\" alt=\"change hostname nmtui\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Set the hostname<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Restart the systemd-hostnamed service for the changes to take effect.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">service systemd-hostnamed restart<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Re-login and verify the hostname change.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Method 4 : Edit \/etc\/hostname<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cat \/etc\/hostname<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">localhost.localdomain<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To change the hostname to \u201cbutterfly\u201d, replace the content of the \/etc\/hostname file with \u201cbutterfly\u201d<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo \"butterfly\" > \/etc\/hostname<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cat \/etc\/hostname<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">butterfly<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Restart the system and verify.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">shutdown -r now<\/pre>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Sources:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>https:\/\/www.thegeekdiary.com\/centos-rhel-7-how-to-change-set-hostname\/<\/li><li>https:\/\/my-hlam.livejournal.com\/34233.html?utm_source=3userpost<\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>For RHEL 6: 1. Change the HOSTNAME\u00a0line in\u00a0\/etc\/sysconfig\/network 2. Change the hostname (FQDN and alias) in\u00a0\/etc\/hosts 3. Run\u00a0\/bin\/hostname new_hostname\u00a0for the hostname change to take effect immediately. 4. Run\u00a0\/sbin\/service syslog restart\u00a0for\u00a0syslog\u00a0to log using the new hostname. A reboot is not required to change the system hostname. For RHEL 7: Method 1 : hostnamectl Get the current &hellip; <a href=\"https:\/\/geckich.space\/?p=159\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Changing hostname on RHEL<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10,7],"tags":[25,154,48,66],"class_list":["post-159","post","type-post","status-publish","format-standard","hentry","category-linux","category-sysadmin","tag-console","tag-hostname","tag-linux","tag-rhel"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts\/159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=159"}],"version-history":[{"count":4,"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts\/159\/revisions"}],"predecessor-version":[{"id":1174,"href":"https:\/\/geckich.space\/index.php?rest_route=\/wp\/v2\/posts\/159\/revisions\/1174"}],"wp:attachment":[{"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geckich.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}