How to change Hostname on Ubuntu

In this beginner's tutorial, we shall see what a hostname is, and how to change it using command-line and GUI ways on your Ubuntu system.

Generally, a hostname is just an assigned name to a computer, laptop, or any other connected device to a network. You can say a hostname is a computer’s nickname, and it is used to identify the machine over the network uniquely.

Sometimes you need to name your computer with a new hostname so it would be easy to recognize it. It is highly recommended not to name two computers on the same network with the same hostname because this would result in a conflict in the network causing issues. The hostname is used to uniquely identify your computer over a network.

In this tutorial, we are going to walk you through changing your Ubuntu machine’s hostname. There are several ways to do it, and we are going to discuss all of them.

Changing your Ubuntu System’s Hostname

We shall look at the command line as well as GUI methods.

Check Computer’s Current Hostname

Before we can start, you can check the current hostname using the following command in the terminal.

hostname

Display Current Hostname
Display Current Hostname

As you can notice, my computer’s current hostname is FOSSLinux. In the next few steps, we are going to change this to a new one.

Change Hostname via Command Line

In this section, you will learn how to change your machine hostname using the command line method using the terminal. There are multiple commands you can use, such as:

  • hostname command
  • hostnamectl command

Change Computer’s Hostname Using hostname Command

Using this method, you will be able to change your computer hostname permanently without even needing to reboot the system.

Step 1. Launch the terminal using this shortcut keys Ctrl + ALT+ T.

Step 2. Use the following hostname command with your the new hostname you need:

sudo hostname FossLinux1

Change Hostname to FossLinux1
Change Hostname

Step 3. Open the hostname configuration file using your favorite editor.

sudo vi /etc/hostname

Open hostname Configruation File
Configuration File

Step 4. Edit the hostname configuration file and add the new hostname:

FossLinux1

Enter Your New Hostname
New Hostname

Step 5. Open the “hosts” configuration file using your favorite editor.

sudo vi /etc/hosts

Open Hosts Configuration File
Open Hosts Configuration File

Now you need to ensure that you have commented on all the old hostnames using the “#” symbol. Then add the new hostname as follows:

127.0.0.1  FossLinux1

Edit Hosts Configuration File
Edit Hosts Configuration File

Step 6. Go and check your hostname now.

Hostname Changed To FossLinux1
Hostname Changed To FossLinux1

Change Computer’s Hostname Using hostnamectl Command

Step 1. Check the current computer hostname using the command:

hostnamectl

Display Current Hostname Using hostnamectl
Display Current Hostname Using hostnamectl

As you can observe, the current computer’s name is FossLinux1, and we are going to change this.

Step 2. Use the hostnamectl to set your computer’s name.

sudo hostnamectl set-hostname FossLinux2

Change Hostname to FossLinux2
Change Hostname to FossLinux2

Step3. Edit the /etc/hosts file using your favorite editor.

sudo vi /etc/hosts

Edit Hosts Configuration File and Add FossLinux2
Edit Hosts Configuration File and Add FossLinux2

Ensure you have commented out the old hostname and add your new hostname as follows:

After Editting Hosts Configuration File and Add FossLinux2
After Editing Hosts Configuration File and Add FossLinux2

Step 4. Check your current hostname.

hostname

Check Current Hostname
Check Current Hostname

Change Hostname Via Graphical User Interface

The easiest method for changing your computer hostname is through the system graphical settings menu.

Step 1. Open the drop-down arrow from the top of the screen.

Open the Arrow
Open the Arrow

Step 2. Select the settings button.

Open System Settings
Open System Settings

Step 3. From the left menu, select the Details menu.

Open Details Menu
Open Details Menu

Step 4. Next, open the About option.

Select The About
Select The About

Step 5. From the right side, you will find your computer’s information. The hostname can be found under the device name.

Device Hostname
Device Hostname

Step 6. Easily you can change the device hostname to a new one.

Change Hostname
Change Hostname

Step 7. Reboot your system.

Step 8. Check your current hostname.

Check Hostname
Check Hostname

Congratulations; you have just learned how to change your computer’s hostname using various methods. That’s it!

Hend Adel
Hi! I'm Hend Adel, a freelancer technical geek with successful experience in Database, Linux and many other IT fields. I help to build solutions to suit business needs and creating streamlined processes. I love Linux and I'm here to share my skills via FOSS Linux! Thanks for reading my article.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

23,241FansLike
389FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

MUST READ

The Ubuntu Cinnamon Remix brings together Linux Mint's Cinnamon desktop with the Ubuntu Core. While some users are welcoming the new flavor of Ubuntu with open arms, others are scratching their heads, wondering where it fits in.
The wait is finally over (almost) for all you Ubuntu fans out there. The latest version of Ubuntu, 20.10 codenamed "Groovy Gorilla," is currently available in the beta version. I have tested out the distro myself, and it is stable enough to take out for a spin.

What’s New in Ubuntu 20.04 LTS “Focal Fossa”

Ubuntu 20.04 LTS is out now! This is the successor to Ubuntu 18.04, which was released in April 2018 and still has three years of official support left. Code-named Focal Fossa, the new edition has all the bells and whistles included in it, making it one of the best Ubuntu releases yet. Let's find out more.

5 Best ways to encrypt files in Linux

Privacy is something that almost all of us have concerns about. Many people switch over to Linux because of its better privacy features. In this time, where many people believe (quite rightly so) that privacy doesn't exist anymore, Linux provides a ray of hope. Distributions like Tails OS are specifically designed for that purpose.

The 10 Best Linux Network Monitoring Tools

Having total control over your network is essential to prevent programs from overusing your network resources and slowing down the overall performance. This is why you should install a network monitoring tool on your system, giving you a visual overview of everything that's happening on your network. Networking Tools are like swiss-knife for the system administrators for troubleshooting system issues.

[Guide] apt vs apt-get commands, and which one to use?

Most Linux users, both veterans, and newbies, often get confused about what the difference between the Linux commands apt, and apt-get are and when they should use one or the other.