{"id":15691,"date":"2019-02-27T15:15:27","date_gmt":"2019-02-27T15:15:27","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=15691"},"modified":"2026-03-10T09:37:13","modified_gmt":"2026-03-10T09:37:13","slug":"linux-change-hostname","status":"publish","type":"post","link":"\/ph\/tutorials\/linux-change-hostname","title":{"rendered":"How to change a hostname in Linux"},"content":{"rendered":"<p>A Linux hostname identifies systems within a network, enabling them to identify and communicate with one another correctly. Assigning a unique hostname is crucial for network management to prevent multiple devices from sharing the same identity, which can cause conflicts and errors.<\/p><p>There are different ways to change a hostname in Linux:<\/p><ul class=\"wp-block-list\">\n<li><strong>Using hostnamectl.<\/strong> Systemd-based modern distributions like Ubuntu, Debian, CentOS 7+ offer a dedicated hostnamectl command to change a hostname.<\/li>\n\n\n\n<li><strong>Editing the configuration file<\/strong>. Your system has a configuration file that defines its current hostname, which you can edit to modify the setting.&nbsp;<\/li>\n\n\n\n<li><strong>Utilizing nmtui<\/strong>. NetworkManager&rsquo;s interactive command-line tool provides an option to change your system&rsquo;s hostname.<\/li>\n\n\n\n<li><strong>Leveraging your hosting control panel.<\/strong> Your Linux server&rsquo;s hosting control panel, like Hostinger&rsquo;s hPanel, may provide an option to change your system&rsquo;s hostname.&nbsp;<\/li>\n<\/ul><p>You can also change the hostname temporarily or permanently, depending on your needs.<\/p><p>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-check-your-current-hostname\"><strong>How to check your current hostname<\/strong><\/h2><p>To check your current Linux system&rsquo;s hostname, use the <strong>hostname<\/strong> or <strong>hostnamectl<\/strong> commands in your terminal.<\/p><p>The <strong>hostname<\/strong> command provides a quick look at the active system name:<\/p><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><p>The output will show your system&rsquo;s current hostname:<\/p><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=\"\">myserver.example.com<\/pre><p>For more details, use <strong>hostnamectl<\/strong>. This command can reveal different types of hostname:<\/p><ul class=\"wp-block-list\">\n<li><strong>Static hostname. <\/strong>The primary, persistent system identity stored in the <strong>\/etc\/hostname<\/strong> file that initializes the kernel during boot. It is essential for network communication and enforces strict syntax rules, prohibiting spaces and special characters.<\/li>\n\n\n\n<li><strong>Pretty hostname. <\/strong>This is a free-form, high-level name stored in <strong>\/etc\/machine-info<\/strong> that supports capitalization, spaces, and special characters. Its purpose is to provide a human-readable description for user interfaces and terminal prompts, without affecting network routing.<\/li>\n\n\n\n<li><strong>Transient hostname<\/strong>. This is a dynamic identity maintained by the Linux kernel that can change during runtime based on network configurations like <strong>DHCP<\/strong> or <strong>mDNS<\/strong>. It typically mirrors the static hostname but acts as a temporary fallback to resolve conflicts if the static name is invalid or duplicated.<\/li>\n<\/ul><p>You can run hostnamectl by itself without any flags or parameters:<\/p><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><p>The output will display detailed information about your system, including its hostnames:<\/p><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=\"\">Static hostname: hostinger-vps\nPretty hostname: Hostinger VPS Server\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Icon name: computer-vm\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Chassis: vm\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Machine ID: 45598cbdb6ee462e8696166b520fe788\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Boot ID: 99526e56aeea45c2a0f3b2ffaaffe9d9\n&nbsp;&nbsp;&nbsp;&nbsp;Virtualization: kvm\n&nbsp;&nbsp;Operating System: Ubuntu 22.04 LTS\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Kernel: Linux 5.15.0-101-generic\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Architecture: x86-64<\/pre><p>Note that the transient hostname will appear only after you set a temporary hostname. You can explicitly tell <strong>hostnamectl <\/strong>to check it like this:<\/p><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 --transient<\/pre><p>The above command will output only the transient hostname of your system. If you haven&rsquo;t set up the temporary hostname, however, it&rsquo;ll simply print the static hostname.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-change-the-hostname-permanently\"><strong>How to change the hostname permanently<\/strong><\/h2><p>Permanently changing the hostname of your Linux system ensures that the new identity persists after a reboot. You typically do this when <a href=\"\/ph\/tutorials\/getting-started-with-vps-hosting\">setting up a new VPS<\/a> whose services require persistent communication, such as mail or web applications.<\/p><p>The easiest way to do it is by running the <strong>hostnamectl <\/strong>command:<\/p><ol class=\"wp-block-list\">\n<li>Access your device&rsquo;s terminal. For a remote system, such as a Linux virtual private server, connect via <strong>SSH<\/strong>.&nbsp;<\/li>\n\n\n\n<li>Run this command to update the static hostname. Replace <strong>new-host-name<\/strong> with your desired name:<\/li>\n<\/ol><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=\"\">sudo hostnamectl set-hostname new-host-name<\/pre><ol start=\"3\" class=\"wp-block-list\">\n<li>Update the<strong> \/etc\/hosts <\/strong>file to ensure your system can resolve to its new hostname to the local loopback address. To edit the file, run:<\/li>\n<\/ol><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=\"\">sudo nano \/etc\/hosts<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Find the line starting with <strong>127.0.0.1<\/strong> or <strong>127.0.1.1<\/strong> and replace the old hostname with the new one:<\/li>\n<\/ol><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=\"\">127.0.0.1 localhost\n\n127.0.1.1 &nbsp; new-host-name<\/pre><ol start=\"5\" class=\"wp-block-list\">\n<li>Press <strong>Ctrl + X<\/strong>, <strong>Y<\/strong>, then<strong> Enter<\/strong> to save the changes.<\/li>\n\n\n\n<li>Check whether the new hostname is assigned by executing:<\/li>\n<\/ol><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><p><div><p class=\"important\"><strong>Important!<\/strong> If your <strong>\/etc\/hosts<\/strong> file only contains <strong>localhost<\/strong> and not the old hostname, you don&rsquo;t need to update it. <\/p><\/div>\n\n\n\n<\/p><p>This method works for modern <a href=\"\/ph\/tutorials\/best-linux-distro\">Linux distributions<\/a> that use <strong>systemd<\/strong>. If your distro uses another init system, you can change the hostname by editing the configuration file manually.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-change-the-hostname-by-editing-configuration-files\"><strong>How to change the hostname by editing configuration files<\/strong><\/h2><p>You can manually edit configuration files to change the hostname on any Linux system. This is particularly useful for legacy distributions or when <strong>hostnamectl<\/strong> is unavailable:<\/p><ol class=\"wp-block-list\">\n<li>Open <strong>\/etc\/hostname<\/strong> using a text editor like nano:<\/li>\n<\/ol><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=\"\">sudo nano \/etc\/hostname<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Delete the existing name and enter your new desired hostname.<\/li>\n\n\n\n<li>Hit <strong>Ctrl + X<\/strong>, <strong>Y<\/strong>, then <strong>Enter<\/strong> to save the file.<\/li>\n\n\n\n<li>Update the <strong>\/etc\/hosts<\/strong> name using the same procedure explained in the previous section.<\/li>\n<\/ol><p>At this point, your hostname is updated. However, you&rsquo;ll need to complete additional steps if you use a cloud system like a <a href=\"\/ph\/vps-hosting\">VPS hosting solution<\/a>, because the provisioning service, like<strong> cloud-init<\/strong>, might reset the settings after reboot. Here&rsquo;s how to preserve the new hostname:<\/p><ol class=\"wp-block-list\">\n<li>Open the cloud configuration file:<\/li>\n<\/ol><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=\"\">sudo nano \/etc\/cloud\/cloud.cfg<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Find the <strong>preserve_hostname<\/strong> parameter and set it to <strong>true<\/strong>:<\/li>\n<\/ol><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=\"\">preserve_hostname: true<\/pre><ol start=\"5\" class=\"wp-block-list\">\n<li>Hit <strong>Ctrl + X<\/strong>, <strong>Y<\/strong>, and <strong>Enter<\/strong> to save the changes.&nbsp;<\/li>\n\n\n\n<li>Apply the changes by restarting your server:<\/li>\n<\/ol><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=\"\">sudo reboot<\/pre><p>Once your system finishes restarting, check the <strong>\/etc\/hostname<\/strong> file to verify that the change has been applied:<\/p><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><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a href=\"\/ph\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner-1024x300.png\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/02\/VPS-hosting-banner.png 1024w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/02\/VPS-hosting-banner-300x88.png 300w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/02\/VPS-hosting-banner-150x44.png 150w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2023\/02\/VPS-hosting-banner-768x225.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-how-to-change-hostname-using-nmtui\"><strong>How to change hostname using nmtui<\/strong><\/h2><p>If you are changing your hostname as part of broader network maintenance or prefer using an interactive interface, use <strong>nmtui<\/strong>. This works similarly to hostnamectl but has an intuitive menu and more network-related options.<\/p><p>Install the tool before proceeding, as it&rsquo;s not pre-installed in all Linux distributions. To do it on a <strong>Debian-based <\/strong>operating system like <strong>Ubuntu<\/strong>, run:<\/p><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=\"\">sudo apt install network-manager<\/pre><p>Meanwhile, run the following if you use <strong>Red Hat Enterprise Linux<\/strong>-based distros like <strong>CentOS <\/strong>and <strong>AlmaLinux<\/strong>:<\/p><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=\"\">sudo dnf install NetworkManager-tui<\/pre><p>Now, change your hostname using <strong>nmtu<\/strong>i:<\/p><ol class=\"wp-block-list\">\n<li>Launch the <strong>nmtui <\/strong>interface by running the following command:<\/li>\n<\/ol><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=\"\">sudo nmtui<\/pre><ol start=\"2\" class=\"wp-block-list\">\n<li>Using your arrow keys, navigate to the <strong>Set system hostname <\/strong>menu<strong>. <\/strong>Hit <strong>Enter<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69dfccdae9fdf\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" width=\"295\" height=\"290\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/02\/The-the-Set-system-hostname-option-on-the-NetworkManager-TUI-window.png\" alt=\"The the Set system hostname option on the NetworkManager TUI window\" class=\"wp-image-53821\" srcset=\"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2019\/02\/The-the-Set-system-hostname-option-on-the-NetworkManager-TUI-window.png 295w, https:\/\/www.hostinger.com\/ph\/tutorials\/wp-content\/uploads\/sites\/44\/2019\/02\/The-the-Set-system-hostname-option-on-the-NetworkManager-TUI-window-150x147.png 150w\" sizes=\"(max-width: 295px) 100vw, 295px\" \/><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><ol start=\"3\" class=\"wp-block-list\">\n<li>Delete the old hostname and enter the new one. Hit <strong>OK<\/strong>.<\/li>\n\n\n\n<li>Hit <strong>OK<\/strong> again on the confirmation message.<\/li>\n\n\n\n<li>Navigate to <strong>Quit <\/strong>and hit <strong>Enter<\/strong>.<\/li>\n\n\n\n<li>Check the hostname to verify that the change has been applied:<\/li>\n<\/ol><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><p>If you want a more interactive method, change your system hostname via your hosting control panel.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-change-hostname-via-hostinger-vps-hpanel\"><strong>How to change hostname via Hostinger VPS hPanel<\/strong><\/h2><p>Hostinger VPS users can change their server&rsquo;s hostname directly from <strong>hPanel<\/strong> without using the command line. This method is the most beginner-friendly and simple because you don&rsquo;t need to access your VPS&rsquo;s terminal. Here&rsquo;s how to do it:<\/p><ol class=\"wp-block-list\">\n<li>Log in to your <strong>Hostinger Account<\/strong> and navigate to the <strong>VPS<\/strong> section on the sidebar.<\/li>\n\n\n\n<li>Click <strong>Manage<\/strong> on the VPS you want to modify.<\/li>\n\n\n\n<li>Scroll down to the <strong>VPS details<\/strong> section.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69dfccdaeb83b\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/02\/the-vps-details-menu-on-hpanel-vps-management-page-1024x692.png\" alt=\"The VPS details menu on hPanel\" class=\"wp-image-137125\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><ol start=\"4\" class=\"wp-block-list\">\n<li>Find the <strong>Hostname<\/strong> setting and click the<strong> pencil <\/strong>icon.&nbsp;<\/li>\n\n\n\n<li>Enter your desired hostname based on the requirement.&nbsp;<\/li>\n\n\n\n<li>Hit <strong>Change<\/strong> to confirm.<\/li>\n<\/ol><p>This process updates the configuration permanently. Once the change takes effect, you&rsquo;ll see it reflected in the VPS details section.<\/p><p>Alternatively, you can ask <a href=\"\/blog\/kodee\">Kodee, our AI assistant<\/a>, to change the hostname for your server like so. Remember to replace <strong>old-hostname<\/strong> and <strong>new-hostname<\/strong> with their actual values:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"atomic\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Change the hostname of my old-hostname VPS to new-hostname.<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69dfccdaecfb2\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2019\/02\/kodee-changes-the-hostname-of-a-server-1024x261.png\" alt=\"Kodee changes the hostname of a server\" class=\"wp-image-137126\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p><div><p class=\"important\"><strong>Important!<\/strong> If you update your VPS hostname via hPanel or Kodee, the change might not be reflected immediately due to the browser cache. However, it should be updated in the background, which you can check using commands via the terminal.<\/p><\/div>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-change-hostname-temporarily-without-reboot\"><strong>How to change hostname temporarily (without reboot)<\/strong><\/h2><p>To temporarily change the hostname of your system, use the <strong>hostname<\/strong> command followed by your desired hostname.<\/p><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=\"\">sudo hostname temporary-name<\/pre><p>To verify the change, run this command:<\/p><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><p>If the change is successful, your terminal will print the new static hostname. This temporary hostname will revert to the value stored in <strong>\/etc\/hostname<\/strong> after you reboot the system.<\/p><p>This method is helpful for quickly testing network scripts or debugging session-specific issues that require a hostname change without altering the permanent server configuration.<\/p><h2 class=\"wp-block-heading\" id=\"h-what-should-you-do-after-changing-your-linux-hostname\"><strong>What should you do after changing your Linux hostname?<\/strong><\/h2><p>After changing the hostname of your Linux server, you should ensure that your connection protocols and network services align with the new identity. Two of the most important steps after updating your hostname are:<\/p><ul class=\"wp-block-list\">\n<li><strong>Updating SSH config<\/strong>. Your local machine uses the&nbsp; <strong>~\/.ssh\/config<\/strong> file to manage SSH connections to remote systems, including storing their hostname. Adjust the file&rsquo;s <strong>Host<\/strong> or <strong>Hostname <\/strong>entries to match the new name to avoid connection errors.<\/li>\n\n\n\n<li><strong>Restarting services<\/strong>. Some services in your system, especially those involving network connections, may still cache the old hostname. Restart them or reboot your system entirely to make sure the change takes effect on all parts of your machine.&nbsp;<\/li>\n<\/ul><p>Changing the hostname is typically a part of a bigger network configuration. While doing so, it&rsquo;s recommended to implement other security practices, such as <a href=\"\/ph\/tutorials\/how-to-change-ssh-port-vps\">changing the SSH port on your VPS<\/a>, to further safeguard your system from various cyberattacks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A Linux hostname identifies systems within a network, enabling them to identify and communicate with one another correctly. Assigning a unique hostname is crucial for network management to prevent multiple devices from sharing the same identity, which can cause conflicts and errors. There are different ways to change a hostname in Linux: You can also [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ph\/tutorials\/linux-change-hostname\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":337,"featured_media":125478,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Change Hostname in Linux","rank_math_description":"Learn how to change hostname in Linux using hostnamectl, nmtui commands and editing configuration files. Steps for doing it without reboot included.","rank_math_focus_keyword":"linux change hostname","footnotes":""},"categories":[22643,22639],"tags":[],"class_list":["post-15691","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-managing-monitoring-and-security","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/linux-change-hostname","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/changer-nom-hote-linux","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/cambiar-hostname-linux","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/linux-change-hostname","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/linux-change-hostname","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/linux-change-hostname","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/cambiar-hostname-linux","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/cambiar-hostname-linux","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/cambiar-hostname-linux","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/linux-change-hostname","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/linux-change-hostname","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/linux-change-hostname","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/linux-change-hostname","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts\/15691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/users\/337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/comments?post=15691"}],"version-history":[{"count":30,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts\/15691\/revisions"}],"predecessor-version":[{"id":125476,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/posts\/15691\/revisions\/125476"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/media\/125478"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/media?parent=15691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/categories?post=15691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ph\/tutorials\/wp-json\/wp\/v2\/tags?post=15691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}