{"id":168,"date":"2011-12-19T09:39:21","date_gmt":"2011-12-19T09:39:21","guid":{"rendered":"http:\/\/test.bleuanus.nl\/index.php\/linux\/change-hostname\/"},"modified":"2018-12-11T16:09:08","modified_gmt":"2018-12-11T15:09:08","slug":"change-hostname","status":"publish","type":"post","link":"https:\/\/www.bleuanus.nl\/index.php\/2011\/12\/19\/change-hostname\/","title":{"rendered":"Change Hostname"},"content":{"rendered":"<p class=\"last-modified\">This post was most recently updated on December 11th, 2018<\/p><h1><a title=\"Permanent Link to How to change the hostname of a Linux system\" rel=\"bookmark\" href=\"http:\/\/www.ducea.com\/2006\/08\/07\/how-to-change-the-hostname-of-a-linux-system\/\"><u><font color=\"#000080\">How to change the hostname of a Linux system<\/font><\/u><\/a><\/h1>\n<p>Normally we will set the <strong>hostname <\/strong>of a system during the installation process. Many peoples don\u2019t care about this, and don\u2019t change the hostname even if for example this was set to something really stupid by the datacenter that installed the system (most likely they will set this to \u201cdebian\u201d on any debian installation, etc). For me, it is important to see on each one of the ssh screens I will have open at any time a different hostname that is relevant and will give me quickly the information on what system I am logged in.<\/p>\n<h3>Change the hostname on a running system<\/h3>\n<p>On any Linux system you can change its hostname with the command \u2018<strong>hostname<\/strong>\u2018 (surprised?)\u2026 Here are some quick usages of the command line hostname:<\/p>\n<pre><code>hostname<\/code><\/pre>\n<p>without any parameter it will output the current hostname of the system.<\/p>\n<pre><code>hostname --fqd<\/code><\/pre>\n<p>it will output the fully qualified domain name (or FQDN) of the system.<\/p>\n<pre><code>hostname NEW_NAME<\/code><\/pre>\n<p>will set the hostname of the system to NEW_NAME. This is active right away and will remain like that until the system will be rebooted (because at system boot it will set this from some particular file configurations \u2013 see bellow how to set this permanently). You will most probably need to exit the current shell in order to see the change in your shell prompt.<\/p>\n<h3>Permanent hostname change on Debian based systems<\/h3>\n<p><strong>Debian <\/strong>based systems use the file <strong>\/etc\/hostname<\/strong> to read the hostname of the system at boot time and set it up using the init script <strong>\/etc\/init.d\/hostname.sh<\/strong><\/p>\n<pre><code><strong>\/etc\/hostname<\/strong>server<\/code><\/pre>\n<p>So on a Debian based system we can edit the file \/etc\/hostname and change the name of the system and then run:<\/p>\n<pre><code>\/etc\/init.d\/hostname.sh start<\/code><\/pre>\n<p>to make the change active. The hostname saved in this file (\/etc\/hostname) will be preserved on system reboot (and will be set using the same script we used hostname.sh).<\/p>\n<h3>Permanent hostname change on RedHat based systems<\/h3>\n<p><strong>RedHat <\/strong>based system use the file <strong>\/etc\/sysconfig\/network<\/strong> to read the saved hostname at system boot. This is set using the init script <strong>\/etc\/rc.d\/rc.sysinit<\/strong><\/p>\n<pre><code><strong>\/etc\/sysconfig\/network<\/strong>NETWORKING=yes<strong>HOSTNAME=\"plain.domainname.com\"<\/strong>GATEWAY=\"192.168.0.1\"GATEWAYDEV=\"eth0\"FORWARD_IPV4=\"yes\"<\/code><\/pre>\n<p>So in order to preserve your change on system reboot edit this file and enter the appropriate name using the HOSTNAME variable.<\/p>\n<h3>Use sysctl to change the hostname<\/h3>\n<p>Why would someone need a different method of doing the same thing as above? No idea, but here is anyway: use <strong>sysctl <\/strong>to change the variable <strong>kernel.hostname<\/strong>:<br \/>Use:<\/p>\n<pre><code>sysctl kernel.hostname<\/code><\/pre>\n<p>to read the current hostname, and<\/p>\n<pre><code>sysctl kernel.hostname=NEW_HOSTNAME<\/code><\/pre>\n<p>to change it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post was most recently updated on December 11th, 2018How to change the hostname of a Linux system Normally we will set the hostname of a system during the installation process. Many peoples don\u2019t care about this, and don\u2019t change the hostname even if for example this was set to something really stupid by the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-168","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/posts\/168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/comments?post=168"}],"version-history":[{"count":1,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/posts\/168\/revisions"}],"predecessor-version":[{"id":244,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/posts\/168\/revisions\/244"}],"wp:attachment":[{"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/media?parent=168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/categories?post=168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bleuanus.nl\/index.php\/wp-json\/wp\/v2\/tags?post=168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}