Adjust your Linux system's host name with ease
Need to modify the name of your Linux computer? Your hostname serves as the identifier for your Linux system on a network. There are numerous methods to change the hostname on Linux, whether through the command line or graphical (GUI) options. Changing your hostname is a quick process, and the changes take effect immediately—no need for a reboot. This guide will walk you through 5 simple ways to set a hostname on any Linux system, including Ubuntu, Redhat, and CentOS.
Key Points to Note
- Utilize 'sudo hostnamectl set-hostname <newhostname>' to change the hostname on Linux.
- If you're using GNOME, you can also adjust the hostname in Settings > About > Device name.
- To check your current hostname, employ the command 'hostnamectl' or 'hostname.'
- For a temporary hostname change, use 'sudo hostname <newhostname>.'
Step-by-Step Instructions
Using the Hostnamectl Command

Access a Terminal. If you're modifying the hostname of a remotely accessed Linux server, log in now. For changing the hostname of your Linux desktop OS, press Ctrl + Alt + T to open a Terminal.
- This method applies to Linux versions utilizing systemd, which encompasses the majority of Linux distributions, such as Ubuntu, Debian, Redhat, CentOS, OpenSUSE, Fedora, and Arch Linux.

Execute the hostnamectl command to check your current hostname. This command shows your current hostname along with system architecture, kernel version, and other details.
- You can alternatively use the command hostname to view your current hostname without additional information.

Execute the command sudo hostnamectl set-hostname newhostname. Substitute newhostname with your desired hostname. After executing the command, your Linux hostname will be immediately updated.
- This command simultaneously updates the static (standard), transient (dynamic), and pretty (descriptive) hostnames. To modify only one type of hostname, utilize the --static, --transient, and --pretty options.
- Static and transient hostnames may only contain letters, numbers, and hyphens.
- Verify your new hostname by running the hostname command. If the hostname remains unchanged, execute sudo systemctl restart systemd-hostnamed to restart systemd-hostnamed.
Utilizing Network Manager CLI

Access a Terminal. If you're altering the hostname of a remotely accessed Linux server, log in now. If you're changing the hostname of your Linux desktop, press Ctrl + Alt + T to open a Terminal window.
- This approach demonstrates how to utilize the Network Manager Command Line Interface (nmcli) to modify the hostname on Linux. Nmcui is available with certain distributions, including RedHat and CentOS.
- On Ubuntu and other Debian-based Linux systems, you can install Network Manager using the command sudo apt install network-manager

Execute the command nmcli general hostname. This command reveals your Linux system's current hostname.

Execute the command sudo nmcli general hostname newhostname. Replace newhostname with your desired hostname, using only letters, numbers, and hyphens. Your new hostname will be applied immediately—no need to reboot.
- To confirm, execute the command hostname.
- If your hostname remains unchanged, run the command sudo systemctl restart systemd-hostnamed to restart systemd-hostnamed.
Using Network Manager TUI

Access a Terminal. If you're modifying the hostname of a remotely accessed Linux server, log in now. If you're changing the hostname of your desktop computer, press Ctrl + Alt + T to open a Terminal window.

Install Network Manager TUI. Here, we'll utilize the Network Manager Text User Interface (nmtui) to alter the hostname. This tool serves as a graphical version of nmcli, but it's not preinstalled on most distributions.
- For Debian-based systems, employ sudo apt install network-manager.
- On Redhat and other RH-based Linux distros, use sudo dnf install NetworkManager-tui.

Execute the command nmtui. This command launches the graphical Network Manager tool.

Select Set system hostname. Navigate using the Tab or arrow keys, and make selections with Enter. Upon selection, your current hostname will appear.

Enter your new hostname and select OK. You've successfully altered the hostname of your Linux system.
- You can confirm your new hostname by executing the hostname command at the prompt.
- If your hostname hasn't changed, execute the command sudo systemctl restart systemd-hostnamed to restart systemd-hostnamed.
GNOME Settings

Access your GNOME settings. If you're utilizing the GNOME desktop environment on Ubuntu, Fedora, or any other Linux version, you can modify the hostname within your settings.

Tap on About. Located on the left panel.
- Your current hostname will be displayed next to 'Device Name.'

Click on Device Name. Now you can replace your existing hostname with a new one.
- Hostnames can include the same characters as domain names—letters, numbers, and hyphens.
- If you input a hostname containing spaces and special characters (e.g., 'My Linux Laptop' instead of linux-laptop), you'll observe that you've set the 'pretty name,' and a new hostname is automatically assigned based on that name (e.g., 'my-linux-laptop'). If you prefer to use a single static hostname for everything, ensure you adhere to typical hostname/domain name conventions.

Input a new hostname and select Rename. Your Linux hostname will be updated instantly.
Using the Hostname Command

Access your Terminal. If you're adjusting the hostname of a server remotely, log in now. For Linux desktop systems, press Ctrl + Alt + T.
- This method allows you to either temporarily modify your hostname or make the change permanent.

Utilize the hostname command to check the current hostname. Besides changing the hostname, running this command without any options shows the current hostname.

Execute the command sudo hostname newhostname. Substitute newhostname with your desired name, which can include letters, numbers, and hyphens.
- Currently, your hostname is only altered temporarily. To make a permanent change without rebooting, proceed with this method.

Modify the hostname in /etc/hostname. Initially, replace your old hostname in /etc/hostname with the new one.
- To access the file, use sudo nano /etc/hostname.
- Replace the old hostname with the new one.
- Press Ctrl + X, then press Y for Yes, and finally press Enter to save and exit.

Adjust the hostname in /etc/hosts. Lastly, replace the old hostname with the new one in /etc/hosts:
- To open the file, execute sudo nano /etc/hosts.
- Scroll down and replace your old hostname (next to 127.0.1.1, not localhost) with the new one.
- Press Ctrl + X, then press Y for Yes, and finally press Enter to save and exit.
- Your Linux hostname change is now permanent.
Helpful Tips
-
While these methods will immediately update your hostname, some apps and services may still reference the old hostname until they are restarted.
-
If a user is remotely logged in during the hostname change, they won't see the new hostname until they initiate a new session.