This simple tutorial will teach you how to change the hostname on Ubuntu. The steps we will tell you here will work for all versions of 16.04 for here including derivatives like Linux Mint or ElementaryOS. Although this is a simple post, it can be useful for anyone who has Ubuntu on a network.
What is the Hostname?
Briefly, a hostname is a unique name for a computer or network connection on a network. This name is a string of characters that help identify a computer on the network. It must be unique since there may be packet loss and some services may not work properly.
In other words, the hostname allows you to distinguish between devices on a local network. Besides, it allows computers to locate others, making it possible to exchange data within a network.
On the other hand, the hostname is used on the Internet as part of the Fully Qualified Domain Name that should not be confused.
But the aim of this post is that we learn how to change it in Ubuntu.
Change the Hostname in Ubuntu
In this tutorial, we will use the terminal. This is so that you can take advantage of it both on a server and your desktop system.
So, open your terminal or start an SSH session. If you use the GNOME interface you can open a terminal by pressing the keys CTRL + ALT + T
Then, check what your hostname is. To do this, run it:
You will get a simple output where you will see the hostname.
If you want a little more information related to the hostname you can use the command hostnamectl
hostnamectl Static hostname: laptop Icon name: computer-laptop Chassis: laptop Machine ID: 16fa2990e5014c52bbca62e8a9eb3558 Boot ID: 25860d46c0c94da5a8a5a344a237d81f
Now, you know what the hostname is in your system, it’s time to change it.
The easiest and most practical way is to use the
hostnamectl command. To change it, follow this syntax:
sudo hostnameclt set-hostname [new-hostname]
sudo hostnameclt set-hostname osradar
And it’s that simple. Check the
hostname command again and you will see the change reflected.
Change the Hostname in Ubuntu permanently
The above method is temporary. This means that when the computer is restarted, the changes will be reversed. To make the change permanent, you have to do the previous step but another one.
After you’ve changed the hostname with the previous command open the file
/etc/hosts and replace any indication of the old hostname with the new one.
sudo nano /etc/hosts
Then, save the changes and reboot the system.
Now the change has been permanent.
Changing the hostname is quite easy but for many it can’t waste any time. So this is important to know and keep in mind for daily work.
So, please share this post and join our Telegram Channel.