{"id":99,"date":"2014-10-19T14:34:49","date_gmt":"2014-10-19T06:34:49","guid":{"rendered":"http:\/\/www.scriptsmy.com\/?p=99"},"modified":"2023-06-23T10:00:20","modified_gmt":"2023-06-23T10:00:20","slug":"how-to-change-hostname-on-centos-7-0rhel-7-0","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-change-hostname-on-centos-7-0rhel-7-0\/","title":{"rendered":"How to Change Hostname on CentOS 7.0\/RHEL 7.0"},"content":{"rendered":"<p>In web hosting environments, the ability to change the hostname of your server is a crucial skill. This tutorial is designed for webmasters and website administrators who are using CentOS 7.0 or RHEL 7.0 on their virtual private servers (VPS). The default hostname for these servers is usually set to <em>localhost.localdomain<\/em>, but there may be instances where you need to change this to a preferred hostname or Fully Qualified Domain Name (FQDN).<\/p>\n<p>This guide will walk you through four different methods to change the hostname on your CentOS 7.0\/RHEL 7.0 server. Each method is detailed and explained step-by-step, ensuring you can follow along regardless of your technical expertise.<\/p>\n<p>Before we dive in, it&#8217;s worth noting that the importance of understanding your server&#8217;s hostname cannot be overstated. The hostname is a label assigned to a device connected to a computer network and is used to distinguish one device from another on a specific network or over the internet. Therefore, knowing how to change your server&#8217;s hostname can be beneficial in many ways, especially when managing multiple servers.<\/p>\n<p>For more in-depth information about different types of web servers, you can visit our articles on <a href=\"https:\/\/webhostinggeeks.com\/blog\/apache-http-server-explained\/\">Apache<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/nginx-server-explained\/\">Nginx<\/a>, and <a href=\"https:\/\/webhostinggeeks.com\/blog\/litespeed-web-server-explained\/\">LiteSpeed<\/a>. If you&#8217;re interested in learning more about different types of hosting, we have comprehensive guides on <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-dedicated-server-hosting\/\">dedicated<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-vps-hosting\/\">VPS<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-cloud-hosting\/\">cloud<\/a>, <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-shared-hosting\/\">shared<\/a>, and even <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-blockchain-hosting-and-how-does-it-work\/\">blockchain<\/a> hosting.<\/p>\n<p>Let&#8217;s get started!<\/p>\n<h2>Method 1: Changing the Hostname Temporarily<\/h2>\n<p>Start by logging into your VPS as a root user.<br \/>\nOnce logged in, type the command hostname followed by your new hostname.<br \/>\nFor example:<\/p>\n<pre>\r\n[root@localhost ~]# hostname mynewhostname.local\r\n[root@localhost ~]# hostname\r\nmynewhostname.local\r\n<\/pre>\n<p>Please note that this change will be lost after a system reboot.<\/p>\n<h2>Method 2: Changing the Hostname Permanently Using hostnamectl<\/h2>\n<p>Log into your VPS as a root user.<br \/>\nUse the hostnamectl set-hostname command followed by your new hostname to change the current hostname.<br \/>\nFor example:<\/p>\n<pre>\r\n[root@localhost ~]# hostnamectl set-hostname ns1.e-webhostinggeeks.com\r\n<\/pre>\n<p>Restart the systemd-hostnamed daemon to make the changes permanent:<\/p>\n<pre>\r\n[root@localhost ~]# systemctl restart systemd-hostnamed\r\n<\/pre>\n<p>Verify the new hostname:<\/p>\n<pre>\r\n[root@localhost ~]# hostnamectl status\r\n Static hostname: ns1.e-webhostinggeeks.com\r\n Icon name: computer-vm\r\n Chassis: vm\r\n Machine ID: 72863e389b584a4dab36fae7f3bffda2\r\n Boot ID: 1cf2f4b5478649549916c0a5bd5d2414\r\n Virtualization: xen\r\n Operating System: CentOS Linux 7 (Core)\r\n CPE OS Name: cpe:\/o:centos:centos:7\r\n Kernel: Linux 3.15.4-x86_64-linode45\r\n Architecture: x86_64\r\n<\/pre>\n<h2>Method 3: Changing the Hostname by Modifying \/etc\/hostname<\/h2>\n<p>Log into your VPS as a root user.<br \/>\nModify the \/etc\/hostname file using your preferred text editor. Replace localhost.localdomain with your preferred hostname or FQDN.<br \/>\nFor example:<\/p>\n<pre>\r\n[root@ns1 ~]# vi \/etc\/hostname\r\n<\/pre>\n<p>Edit the file to include your new hostname:<\/p>\n<pre>\r\nns1.e-webhostinggeeks.com\r\n<\/pre>\n<p>Verify the change by opening another terminal session and typing hostname:<\/p>\n<pre>\r\n[root@ns1 ~]# hostname\r\nns1.e-webhostinggeeks.com\r\n<\/pre>\n<h2>Method 4: Changing the Hostname Using nmtui<\/h2>\n<p>Log into your VPS as a root user.<br \/>\nType nmtui in the terminal.<\/p>\n<pre>\r\n[root@ns1 ~]# nmtui\r\n<\/pre>\n<p>A text user interface will appear.<br \/>\nUse the arrow keys to select &#8220;Set system hostname&#8221; and press tab to select OK.<br \/>\nA confirmation message will appear. Press OK to complete the change.<\/p>\n<h2>Commands Mentioned<\/h2>\n<ul>\n<li><span class=\"fw-bold\">hostname<\/span> \u2013 Displays the current hostname or sets a new one temporarily.<\/li>\n<li><span class=\"fw-bold\">hostnamectl set-hostname<\/span> \u2013 Sets a new hostname permanently.<\/li>\n<li><span class=\"fw-bold\">systemctl restart systemd-hostnamed<\/span> \u2013 Restarts the systemd-hostnamed daemon to apply the new hostname permanently.<\/li>\n<li><span class=\"fw-bold\">vi \/etc\/hostname<\/span> \u2013 Opens the \/etc\/hostname file for editing.<\/li>\n<li><span class=\"fw-bold\">nmtui<\/span> \u2013 Opens the NetworkManager&#8217;s Text User Interface.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>Changing the hostname on your CentOS 7.0\/RHEL 7.0 server is a straightforward process once you understand the steps involved. Whether you need to make a temporary change or a permanent one, this guide provides you with four different methods to accomplish this task.<\/p>\n<p>Remember, the hostname of your server plays a crucial role in network identification. Therefore, it&#8217;s essential to ensure that it accurately represents your server&#8217;s purpose or function, especially when managing multiple servers.<\/p>\n<p>We hope this tutorial has been informative and helpful. If you have any questions or need further assistance, feel free to reach out.<\/p>\n<p>Happy hosting!<\/p>\n<h2>FAQ<\/h2>\n<ol itemscope itemtype=\"https:\/\/schema.org\/FAQPage\">\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is a hostname?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">A hostname is a label assigned to a device connected to a computer network. It is used to distinguish one device from another on a specific network or over the internet.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Why would I need to change my server&#8217;s hostname?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">Changing your server&#8217;s hostname can be beneficial in many ways, especially when managing multiple servers. It allows you to easily identify and distinguish between different servers.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the difference between a temporary and a permanent hostname change?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">A temporary hostname change will only last until the next system reboot, at which point the hostname will revert back to its previous state. A permanent hostname change, on the other hand, will persist even after a system reboot.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is the \/etc\/hostname file?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">The \/etc\/hostname file is a system configuration file in Linux that contains the hostname of the system. It is one of the files that can be edited to change the hostname permanently.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is nmtui?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">nmtui stands for NetworkManager Text User Interface. It is a command-line utility that provides a text interface to configure networking by controlling NetworkManager, which can be used to change the hostname among other things.<\/span>\n            <\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In web hosting environments, the ability to change the hostname of your server is a crucial skill. This tutorial is designed for webmasters and website administrators who are using CentOS&#8230;<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[996],"tags":[1259,1414,1536,1718],"class_list":["post-99","post","type-post","status-publish","format-standard","hentry","category-linux","tag-centos-7-0","tag-hostname","tag-linux","tag-rhel-7-0"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/99","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=99"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/99\/revisions"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}