{"id":21971,"date":"2023-10-01T05:07:32","date_gmt":"2023-10-01T05:07:32","guid":{"rendered":"https:\/\/linuxways.net\/?p=21971"},"modified":"2023-10-01T05:07:32","modified_gmt":"2023-10-01T05:07:32","slug":"how-to-set-hostname-variable-in-linux-ubuntu","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-set-hostname-variable-in-linux-ubuntu\/","title":{"rendered":"How to Set Hostname Variable in Linux\/Ubuntu?"},"content":{"rendered":"<p>A <strong>hostname<\/strong> is a unique user-generated name used for the identification of a host on a network. Users have the option to set the hostname during the installation of Ubuntu 22.04. There are situations, where a user might require to set up a hostname, for example, on a certain network, two computers have the same hostname. In these situations, in order to avoid network conflict, a change of hostname is required.<\/p>\n<p>This article will demonstrate setting up a hostname on Linux\/Ubuntu 22.04 LTS as below:<\/p>\n<ul>\n<li>How to Set a Hostname for the Current Session Using Command Line?<\/li>\n<li>How to Set a Hostname Permanently Using the Command Line?<\/li>\n<li>How to Set a Hostname Using NMTUI (Network Manager TUI)?<\/li>\n<li>How to Set a Hostname Using GUI (Graphical User Interface)?<\/li>\n<\/ul>\n<h2><a id=\"post-21971-_nekp12wj7fpk\"><\/a>How to Check the Hostname of a System in Linux\/Ubuntu 22.04?<\/h2>\n<p>A hostname can be checked by using the below-stated command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">hostname<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"127\" class=\"wp-image-21972\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-1.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-1-300x19.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-1-1024x64.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-1-768x48.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-1-1536x95.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the above image, it can be seen that the hostname of the system is \u201cubuntu\u201d. Additionally, additional information about the system can be viewed by using the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span>hostnamectl<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"689\" class=\"wp-image-21973\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-2.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-2-300x101.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-2-1024x345.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-2-768x258.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-2-1536x517.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<h2><a id=\"post-21971-_5c0o2c1s84w1\"><\/a>How to Set a Hostname for the Current Session Using Command Line?<\/h2>\n<p>A hostname can be set for the current session by executing the below command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span>hostnamectl set-hostname ubuntu-test<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1878\" height=\"130\" class=\"wp-image-21974\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-3.png 1878w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-3-300x21.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-3-1024x71.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-3-768x53.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-3-1536x106.png 1536w\" sizes=\"auto, (max-width: 1878px) 100vw, 1878px\" \/><\/p>\n<p>From the above image, it can be seen that the command is executed successfully. However, the changes will be in effect after restarting the terminal as seen below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1682\" height=\"152\" class=\"wp-image-21975\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-4.png 1682w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-4-300x27.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-4-1024x93.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-4-768x69.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-4-1536x139.png 1536w\" sizes=\"auto, (max-width: 1682px) 100vw, 1682px\" \/><\/p>\n<p>It can be seen from the image above, that the hostname is changed from ubuntu to ubuntu-test. The hostname set by \u201chostnamectl\u201d is temporary and no boot is required for changes to be in effect.<\/p>\n<h2><a id=\"post-21971-_fetx9rtygpsu\"><\/a>How to Set a Hostname Permanently Using the Command Line?<\/h2>\n<p>The hostname can be changed permanently by editing the following configuration files:<\/p>\n<ul>\n<li>\/etc\/hostname<\/li>\n<li>\/etc\/hosts<\/li>\n<\/ul>\n<p>These files can be edited by the following steps:<\/p>\n<h3><a id=\"post-21971-_tbq08z1dh35g\"><\/a>Step 1: Edit \/etc\/hostname Configuration File<\/h3>\n<p>\/etc\/hostname configuration file can be edited by using a text editor, for example, nano:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">nano<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span><span class=\"kw2\">hostname<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1672\" height=\"108\" class=\"wp-image-21976\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-5.png 1672w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-5-300x19.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-5-1024x66.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-5-768x50.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-5-1536x99.png 1536w\" sizes=\"auto, (max-width: 1672px) 100vw, 1672px\" \/><\/p>\n<p>The \/etc\/hostname configuration file contains only the current hostname. This hostname can be edited.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1706\" height=\"1094\" class=\"wp-image-21977\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-6.png 1706w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-6-300x192.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-6-1024x657.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-6-768x492.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-6-1536x985.png 1536w\" sizes=\"auto, (max-width: 1706px) 100vw, 1706px\" \/><\/p>\n<p>It can be seen from the above figure that the current hostname is ubuntu-test. This hostname can be modified:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1708\" height=\"1088\" class=\"wp-image-21978\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-7.png 1708w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-7-300x191.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-7-1024x652.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-7-768x489.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-7-1536x978.png 1536w\" sizes=\"auto, (max-width: 1708px) 100vw, 1708px\" \/><\/p>\n<p>From the above figure, it can be seen that the hostname is modified from ubuntu-test to ubuntu. After the edit, the file is saved and closed by pressing Ctrl+O and Ctrl+X respectively.<\/p>\n<h3><a id=\"post-21971-_mv6biauxsvr9\"><\/a>Step 2: Edit \/etc\/hosts Configuration File<\/h3>\n<p>\/etc\/hosts configuration file can be edited by using a Nano text editor by executing the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">nano<\/span> <span class=\"sy0\">\/<\/span>etc<span class=\"sy0\">\/<\/span>hosts<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1656\" height=\"102\" class=\"wp-image-21979\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-8.png 1656w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-8-300x18.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-8-1024x63.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-8-768x47.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-8-1536x95.png 1536w\" sizes=\"auto, (max-width: 1656px) 100vw, 1656px\" \/><\/p>\n<p>The \/etc\/hosts configuration file contains hostname along with other information:<\/p>\n<h3><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1706\" height=\"1100\" class=\"wp-image-21980\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-9.png 1706w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-9-300x193.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-9-1024x660.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-9-768x495.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-9-1536x990.png 1536w\" sizes=\"auto, (max-width: 1706px) 100vw, 1706px\" \/><\/p>\n<p>From the above image, we can see that the hostname is present in the second line of the file and can be edited:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1696\" height=\"1092\" class=\"wp-image-21981\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-10.png 1696w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-10-300x193.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-10-1024x659.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-10-768x494.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-10-1536x989.png 1536w\" sizes=\"auto, (max-width: 1696px) 100vw, 1696px\" \/><\/p>\n<p>The hostname is updated from ubuntu-test to ubuntu. After the edit, the file is saved and closed by pressing Ctrl+O and Ctrl+X respectively.<\/p>\n<h3><a id=\"post-21971-_6lz023100gqd\"><\/a>Step 3: Reboot System<\/h3>\n<p>After edits in \/etc\/hostname and \/etc\/hosts configuration files, the system is rebooted:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> systemctl reboot<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1880\" height=\"92\" class=\"wp-image-21982\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-11.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-11.png 1880w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-11-300x15.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-11-1024x50.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-11-768x38.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-11-1536x75.png 1536w\" sizes=\"auto, (max-width: 1880px) 100vw, 1880px\" \/><\/p>\n<p>The changes are applied after the system boot. The hostname can be verified by running the below command: <img loading=\"lazy\" decoding=\"async\" width=\"1682\" height=\"146\" class=\"wp-image-21983\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-12.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-12.png 1682w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-12-300x26.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-12-1024x89.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-12-768x67.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-12-1536x133.png 1536w\" sizes=\"auto, (max-width: 1682px) 100vw, 1682px\" \/><\/p>\n<p>From the above figure, it can be verified that the hostname is changed from ubuntu-test to ubuntu.<\/p>\n<h2><a id=\"post-21971-_a8i8xmrekf3p\"><\/a>How to Set a Hostname Using NMTUI (Network Manager TUI)?<\/h2>\n<p><strong>NMTUI (Network Manager TUI) <\/strong>is a graphical command-line utility that allows us to easily configure network interfaces in Linux\/Ubuntu. It can be used to set a hostname permanently. NMTUI tool can be launched by executing the \u201cnmtui\u201d command in the terminal:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span>nmtui<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1700\" height=\"102\" class=\"wp-image-21984\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-13.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-13.png 1700w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-13-300x18.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-13-1024x61.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-13-768x46.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-13-1536x92.png 1536w\" sizes=\"auto, (max-width: 1700px) 100vw, 1700px\" \/><\/p>\n<p>After NMTUI is launched, the option \u201cSet system hostname\u201d can be selected and then \u201cOK\u201d:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1688\" height=\"1098\" class=\"wp-image-21985\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-14.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-14.png 1688w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-14-300x195.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-14-1024x666.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-14-768x500.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-14-1536x999.png 1536w\" sizes=\"auto, (max-width: 1688px) 100vw, 1688px\" \/><\/p>\n<p>There will be a prompt to Set Hostname and any name can be typed here:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1694\" height=\"1082\" class=\"wp-image-21986\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-15.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-15.png 1694w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-15-300x192.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-15-1024x654.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-15-768x491.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-15-1536x981.png 1536w\" sizes=\"auto, (max-width: 1694px) 100vw, 1694px\" \/><\/p>\n<p>After typing hostname in \u201cHostname\u201d field, OK will be selected to proceed with the process:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1690\" height=\"1090\" class=\"wp-image-21987\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-16.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-16.png 1690w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-16-300x193.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-16-1024x660.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-16-768x495.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-16-1536x991.png 1536w\" sizes=\"auto, (max-width: 1690px) 100vw, 1690px\" \/><\/p>\n<p>A user password will be required for authentication:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1806\" height=\"1162\" class=\"wp-image-21988\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-17.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-17.png 1806w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-17-300x193.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-17-1024x659.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-17-768x494.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-17-1536x988.png 1536w\" sizes=\"auto, (max-width: 1806px) 100vw, 1806px\" \/><\/p>\n<p>After authentication, there will be a prompt to press \u201cOK\u201d in order to confirm:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1622\" height=\"1018\" class=\"wp-image-21990\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-18.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-18.png 1622w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-18-300x188.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-18-1024x643.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-18-768x482.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-18-1536x964.png 1536w\" sizes=\"auto, (max-width: 1622px) 100vw, 1622px\" \/><\/p>\n<p>From the above image, it can be seen that the hostname is changed from \u201cubuntu-test\u201d to \u201cubuntu\u201d. These changes will be in effect after restarting the terminal:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1682\" height=\"146\" class=\"wp-image-21991\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-19.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-19.png 1682w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-19-300x26.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-19-1024x89.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-19-768x67.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-19-1536x133.png 1536w\" sizes=\"auto, (max-width: 1682px) 100vw, 1682px\" \/><\/p>\n<p>It can be seen that after restarting the terminal the hostname is changed.<\/p>\n<h2><a id=\"post-21971-_hvchufqbk05t\"><\/a>How to Set Hostname Using GUI (Graphical User Interface)?<\/h2>\n<p>The hostname can be changed by Ubuntu\u2019s GUI (Graphical User Interface) fairly easily by naviating to \u201cSettings\u201d and then \u201cAbout\u201d:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1958\" height=\"1638\" class=\"wp-image-21992\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-20.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-20.png 1958w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-20-300x251.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-20-1024x857.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-20-768x642.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-20-1536x1285.png 1536w\" sizes=\"auto, (max-width: 1958px) 100vw, 1958px\" \/><\/p>\n<p>From the above image, it can be seen that the current device name (or hostname) is \u201cubuntu\u201d. By clicking the \u201cubuntu\u201d button, a new dialog box will appear to replace the current \u201chostname\u201d:<\/p>\n<h1><a id=\"post-21971-_f3h5m1x94s6x\"><\/a><img loading=\"lazy\" decoding=\"async\" width=\"510\" height=\"292\" class=\"wp-image-21993\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-21.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-21.png 510w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-21-300x172.png 300w\" sizes=\"auto, (max-width: 510px) 100vw, 510px\" \/><\/h1>\n<p>The hostname can be changed with a new hostname and it can be confirmed by pressing the \u201cRename\u201d button. This changes the hostname permanently. Further, the change can be verified by checking the About section:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1258\" height=\"650\" class=\"wp-image-21994\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-22.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-22.png 1258w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-22-300x155.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-22-1024x529.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21971-22-768x397.png 768w\" sizes=\"auto, (max-width: 1258px) 100vw, 1258px\" \/><\/p>\n<p>From the above figure, it can be seen that the hostname is modified from ubuntu to ubuntu-testhost.<\/p>\n<h2><a id=\"post-21971-_k4r3ojha6hv3\"><\/a>Conclusion<\/h2>\n<p>Hostnames are set using the command line, NMTUi tool, and GUI. Hostnames are set permanently using the nmtui tool, Ubuntus GUI, and by editing \u201cetc\/hostname\u201d and \u201cetc\/hosts\u201d configuration files, while the \u201chostnamectl\u201d command is used to set the hostname for the current session. This article has demonstrated setting up a hostname on Linux\/Ubuntu 22.04 LTS.<\/p>","protected":false},"excerpt":{"rendered":"<p>Hostname are set by nmtui tool, GUI, and by editing \u201cetc\/hostname\u201d and \u201cetc\/hosts\u201d files permanently, while by \u201chostnamectl\u201d command for the current session. <\/p>","protected":false},"author":110,"featured_media":21989,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1049,2],"tags":[],"class_list":["post-21971","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux-commands","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/21971","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=21971"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/21971\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/21989"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=21971"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=21971"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=21971"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}