How to Change the Hostname in Linux

Linux users tend to use several technical jargon that originated from when the kernel was developed. Take Hostname as an example, which is a technical term for your PC’s name. Now, if you’ve been using computers and other smart gadgets, it’s easy to take a guess. But if you are a novice Linux user, changing the “hostname” might sound like a complicated adventure, but we’re here to help you. In this guide, let’s look at how to change the hostname in Linux.

How to Check Your Hostname in Linux

Hostname is set while installing the distro when the installer asks you to insert a name for your machine. Launch the Terminal and type the following command to find out your hostname in Linux.


In addition to the hostname command, there is another way to check Hostname in Linux using the cat command. Your PC’s Hostname is stored in the hostname text file under the /etc directory, which contains Linux’s configuration files. Launch the Linux Terminal and type the following command:

cat /etc/hostname
Check hostname in Linux using hostname and cat command

You could also go to the Settings app -> About -> Device Name to check your Hostname on Linux.

How to Change Your Hostname in Linux (3 Ways)

Here are three different methods to change the Hostname on your Linux machine. Let’s start with the command line method.

1. Change Hostname using Terminal

Since the Hostname file in /etc stores your Hostname, changing the contents of the file will also change the hostname in Linux. While this isn’t possible using GUI, it can be done using your favorite Linux text editor in the Terminal.

1. Launch the terminal and enter the following command. We are using Nano here for demonstration purposes.

sudo nano /etc/hostname

2. Edit the first line and start typing the new hostname.

Change hostname in terminal

3. Once done, press Ctrl+O to enter the saving mode, enter to save the name of the file, and Ctrl+X to exit the file.

Save the file name Linux

4. Voila! You have changed the Hostname of your Linux PC using the Terminal.

2. Change the Hostname in the Settings app

Popular desktop environments such as GNOME and KDE allow you to change the hostname of your Linux machine right from the Settings app. We were using a Fedora installation which uses GNOME and here’s how it’s done.

1. Go to Settings -> About and click on the Device Name text field.

Fedora Device name in settings

2. Start entering a new name. Once done, click the check icon.

Change the name and click on the tick icon

3. Using Hostnamectl Command

Hostnamectl or Control the Hostname is a command that’s used to display or change the values pertaining to the information of your Linux desktop. Hence, it can be used to change the hostname of your Linux PC. To do so, type the following command.

hostnamectl set-hostname "Abubakar's Fedora Machine"
Hostnamectl command to change the hostname
comment Comments 0
Leave a Reply