PDF download Download Article
Change your Linux system's host name in a few simple steps
PDF download 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 wikiHow 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

PDF download Download Article
  1. 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 . [1]
    • 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. This displays your current hostname, along with your system architecture, kernel version, and other info. [2]
    • You can also run the command hostname to view your current hostname without any additional info.
    Advertisement
  3. Replace newhostname with the hostname you'd like to set. Once you run the command, your Linux hostname will be changed immediately. [3]
    • 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. [4]
    • 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

PDF download Download Article
  1. 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. [5]
    • 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. This displays your Linux system's current hostname. [6]
  3. 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

PDF download Download Article
  1. 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. [7]
  2. 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. This launches the graphical Network Manager tool. [8]
  4. You can navigate by pressing the Tab or arrow keys, and make selections using Enter . Once selected, your current hostname will appear.
  5. 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

PDF download Download Article
  1. 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. It's on the left panel. [9]
    • You'll see your current hostname next to "Device Name."
  3. Now you'll be able to replace your old hostname with a new one. [10]
    • 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. [11]
  4. Your Linux hostname will update instantly.
  5. Advertisement
Method 5
Method 5 of 5:

The Hostname Command

PDF download Download Article
  1. 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. [12]
    • You can use this method to temporarily change your hostname or make the change permanent.
  2. While you'll also be using this command to change the hostname, running it without any options simply displays the current hostname. [13]
  3. Replace newhostname with the name you want to give your Linux system. Hostnames can include letters, numbers, and dashes (hyphens). [14]
    • 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. 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. The last step is to replace the old hostname with the new one in /etc/hosts: [15]
    • 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
      Advertisement

      Video

      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. [16]
      • 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
      Name
      Please provide your name and last initial
      Thanks for submitting a tip for review!
      Advertisement

      About This Article

      Thanks to all authors for creating a page that has been read 58,832 times.

      Is this article up to date?

      Advertisement