How To Change The Hostname In Linux 2024 Guide
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:
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.
- Launch the terminal and enter the following command. We are using Nano here for demonstration purposes.
- Edit the first line and start typing the new hostname.
- 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.
- 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.
- Go to Settings -> About and click on the Device Name text field.
- Start entering a new name. Once done, click the check 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.