How to Change the Hostname on Linux Without Rebooting

Download Article
Change your Linux system's host name in a few simple steps
Download Article

Do you need to change the name of your Linux computer? Your hostname is the name that identifies your Linux system on a network. There are many ways to change the hostname on Linux, both from the command line and using graphical (GUI) options. Changing your hostname only takes a few seconds, and the change will take effect right away—no reboot required. This How.com.vn article will teach you 5 easy ways to set a hostname on any Linux system, including Ubuntu, Redhat, and CentOS.

Things You Should Know

  • Use "sudo hostnamectl set-hostname <newhostname>" to change the hostname on Linux.
  • If you use GNOME, you can also set a hostname in Settings > About > Device name.
  • To view your current hostname, use the command "hostnamectl" or "hostname."
  • For a temporary hostname change, use "sudo hostname <newhostname>."
Method 1
Method 1 of 5:

The Hostnamectl Command

Download Article
  1. How.com.vn English: Step 1 Open a Terminal.
    If you're changing the hostname of a Linux server that you're signing in to remotely, log in now. If you're changing the hostname of your Linux desktop operating system, press Ctrl + Alt + T to open a Terminal.
    • This method will work on any version of Linux that uses systemd, which is the majority of Linux distributions. This includes Ubuntu, Debian, Redhat, CentOS, OpenSUSE, Fedora, and Arch Linux.
  2. How.com.vn English: Step 2 Run the hostnamectl command to view your current hostname.
    This displays your current hostname, along with your system architecture, kernel version, and other info.[1]
    • You can also run the command hostname to view your current hostname without any additional info.
    Advertisement
  3. How.com.vn English: Step 3 Run the command sudo hostnamectl set-hostname newhostname.
    Replace newhostname with the hostname you'd like to set. Once you run the command, your Linux hostname will be changed immediately.
    • This command changes the static (standard), transient (dynamic), and pretty (descriptive) hostnames all at once. If you only want to change one type of hostname, you can use the --static, --transient, and --pretty options.
    • Static and transient hostnames can contain letters, numbers, and hyphens only.[2]
    • Run the hostname command to see your new hostname. If the hostname hasn't changed run the command sudo systemctl restart systemd-hostnamed to restart systemd-hostnamed.
  4. Advertisement
Method 2
Method 2 of 5:

Network Manager CLI

Download Article
  1. How.com.vn English: Step 1 Open a Terminal.
    If you're changing the hostname of a Linux server that you're signing in to remotely, log in now. If you're changing the hostname of your Linux desktop operating system, press Ctrl + Alt + T to open a Terminal.
    • This method will show you how to use the Network Manager Command Line Interface (nmcli) to change the hostname on Linux. Nmcui comes with some distributions, including RedHat and CentOS.
    • You can install Network Manager on Ubuntu and other Debian-based Linux systems using the command sudo apt install network-manager.
  2. How.com.vn English: Step 2 Run the command nmcli general hostname.
    This displays your Linux system's current hostname.[3]
  3. How.com.vn English: Step 3 Run the command sudo nmcli general hostname newhostname.
    Replace newhostname with the hostname you'd like to set, using only letters, numbers, and hyphens. Your new hostname will be set instantly—no reboot required.
    • To verify, run the command hostname.
    • If your hostname has not changed, run the command sudo systemctl restart systemd-hostnamed to restart systemd-hostnamed.
  4. Advertisement
Method 3
Method 3 of 5:

Network Manager TUI

Download Article
  1. How.com.vn English: Step 1 Open a Terminal.
    If you're changing the hostname of a Linux server that you're signing in to remotely, log in now. If you're changing the hostname of your desktop computer, press Ctrl + Alt + T to open a Terminal.
  2. How.com.vn English: Step 2 Install Network Manager TUI.
    In this method, we'll use the Network Manager Text User Interface (nmtui) to change the hostname. This tool is a graphical version of nmcli, but it isn't preinstalled on most distributions.
    • To install on Debian-based systems, use sudo apt install network-manager.
    • On Redhat and other RH-based Linux distros, use sudo dnf install NetworkManager-tui.
  3. How.com.vn English: Step 3 Run the command nmtui.
    This launches the graphical Network Manager tool.[4]
  4. How.com.vn English: Step 4 Select Set system hostname.
    You can navigate by pressing the Tab or arrow keys, and make selections using Enter. Once selected, your current hostname will appear.
  5. How.com.vn English: Step 5 Enter your new hostname and select OK.
    You have now changed the hostname of your Linux system.
    • You can verify your new hostname by running the hostname command at the prompt.
    • If your hostname is not changed, run the command sudo systemctl restart systemd-hostnamed to restart systemd-hostnamed.
  6. Advertisement
Method 4
Method 4 of 5:

GNOME Settings

Download Article
  1. How.com.vn English: Step 1 Open your GNOME settings.
    If you're using the GNOME desktop environment on Ubuntu, Fedora, or any other version of Linux, you can change the hostname in your settings.
  2. How.com.vn English: Step 2 Click About.
    It's on the left panel.
    • You'll see your current hostname next to "Device Name."
  3. How.com.vn English: Step 3 Click Device Name.
    Now you'll be able to replace your old hostname with a new one.
    • Hostnames can contain the same characters as domain names—letters, numbers, and hyphens.
    • If you enter a hostname that has spaces and special characters (e.g., "My Linux Laptop" instead of linux-laptop), you'll see that you've set the "pretty name," and that a new hostname is automatically assigned based on that name (e.g., "my-linux-laptop"). If you want to use one static hostname for everything, make sure to stick to the typical hostname/domain name conventions.[5]
  4. How.com.vn English: Step 4 Enter a new hostname and click Rename.
    Your Linux hostname will update instantly.
  5. Advertisement
Method 5
Method 5 of 5:

The Hostname Command

Download Article
  1. How.com.vn English: Step 1 Open a Terminal.
    If you're changing the hostname of a server that you're signing in to remotely, log in now. If you're changing the hostname of your Linux desktop operating system, press Ctrl + Alt + T to open a Terminal.
    • You can use this method to temporarily change your hostname or make the change permanent.
  2. How.com.vn English: Step 2 Use the hostname command to view the current hostname.
    While you'll also be using this command to change the hostname, running it without any options simply displays the current hostname.
  3. How.com.vn English: Step 3 Run the command sudo hostname newhostname.
    Replace newhostname with the name you want to give your Linux system. Hostnames can include letters, numbers, and dashes (hyphens).
    • As of now, your hostname is only changed temporarily. If you were to reboot now, the old hostname would return. If you want to change your Linux hostname permanently without rebooting, continue with this method.
  4. How.com.vn English: Step 4 Update the hostname in /etc/hostname.
    The first step of making your hostname change permanent is to replace your old hostname in /etc/hostname with the new hostname.
    • To open the file, run sudo nano /etc/hostname.
    • Replace the old hostname with the new one.
    • Press Ctrl + X, press Y for Yes, and then press Enter to save and exit.
  5. How.com.vn English: Step 5 Update the hostname in /etc/hosts.
    The last step is to replace the old hostname with the new one in /etc/hosts:
    • To open the file, run sudo nano /etc/hosts.
    • Scroll down and replace your old hostname (the one next to 127.0.1.1 that is not localhost) with the new one.
    • Press Ctrl + X, press Y for Yes, and then press Enter to save and exit.
    • Your Linux hostname change is now permanent.
  6. Advertisement

Expert Q&A

Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
      Advertisement

      Tips

      • Although these methods will change your hostname right away, some of your apps and services may still see the old hostname until you restart them.[6]
      • If a user is logged in remotely when you change the hostname, they won't see the new hostname until they log in to a new session.
      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!
      Advertisement

      About This Article

      How.com.vn English: Stan Kats
      Written by:
      Cybersecurity Expert
      This article was written by Stan Kats and by How.com.vn staff writer, Nicole Levine, MFA. Stan Kats is the COO and Chief Technologist for The STG IT Consulting Group in West Hollywood, California. Stan provides comprehensive technology & cybersecurity solutions to businesses through managed IT services, and for individuals through his consumer service business, Stan's Tech Garage. Stan has over 7 years of cybersecurity experience, holding senior positions in information security at General Motors, AIG, and Aramark over his career. Stan received a BA in International Relations from The University of Southern California. This article has been viewed 26,917 times.
      How helpful is this?
      Co-authors: 3
      Updated: June 27, 2023
      Views: 26,917
      Categories: Software
      Thanks to all authors for creating a page that has been read 26,917 times.

      Is this article up to date?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement