How to Change Hostname in Ubuntu

How to Change Hostname in Ubuntu

Are you looking to change hostname in Linux? That is a good idea. But do you know “What is hostname? Why do you want to change hostname? or How to change hostname in Ubuntu or other Linux Operating System.

In simple word hostname is a computer name of your laptop of desktop or other devices have Linux OS.

If you remember, You set the hostname / computer name at time when you was installing of Ubuntu.

But Now, You don’t like that hostname by any reason and want to change it without restarting Ubuntu system. Yest you can change hostname easily by using command line as well as using GUI (Graphical Interface)

This article completely for beginners, because I cover how to change hostname by using GUI and What to do after changing hostname.

Check hostname in Ubuntu Linux

When you open terminal, you will something writing on terminal windows. Looks like following


In above example you can see the written content vijay@Ubuntu-19.

Here before @ is user name (vijay) and after @ is hostname (Ubuntu-19). This is the easiest way to identify hostname.

Use following command to check hostname


   Static hostname: ubuntu19
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 6a2d54d27ada43438ae08aab40971081
           Boot ID: f19523f35db04406bb7a2f76b6c221fc
    Virtualization: oracle
  Operating System: Ubuntu 19.04
            Kernel: Linux 5.0.0-16-generic
      Architecture: x86-64
vijay@Ubuntu-19:~$sudo cat /etc/hosts
[sudo] password for vijay:	localhost	ubuntu19

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Change hostname in Ubuntu by using the hostname command

You have check your hostname but you dont like it anymore and you want to change it. Right?

You must have root user / Sudo user to perform this action. following command is used to set the new hostname.

$sudo hostname LinuxOS

vijay@Ubuntu-19:~$sudo hostname LinuxOS

I have changed hostname from Ubunut-19 to LinuxOS. You can check hostname

Change hostname in Ubuntu using hostnamectl

If you not able to change hostname by using hostname command then Don’t worry. Linux has another utility to chnage computer name. It is hostnamectl.

You can use command hostnamectl set-hostname [Host Name Here}

I am going to change hostname to UbuntuOS, So i will execute following syntax.

$sudo hostnamectl set-hostname UbuntuOS

vijay@Ubuntu-19:~$sudo hostnamectl set-hostname UbuntuOS

Use GUI to Change hostname in Ubuntu Linux

Most of user in this world love using of graphical interface, So I decide to add this graphical section in this article.

Graphical interface is awesome and probably very easy to use.

First step to check hostname, and Sorry, I will have to use command line interface to check host name.


You are only three 4 clicks away to change it. And only 3 Steps are here.

Step 1: Go to the settings by click on top-right icons then click on setting icon.


Step 2: Select about option from left side bar


Step 3: Give the new device name and close it. It will save automatic.


Next After Change Hostname in Ubuntu

After change host name you have done everything is not right. Here is one more step you have done to get identify in network.

Make the entry of new hostname in file /etc/hosts. You can use any Text editor to make this change.

I am going to use nano text editor for this task. My old hostname was CentOS. I will change it to Ubuntu-19
Edit this line New-hostname

vijay@Ubuntu-19:~$sdo nano /etc/hosts
$       localhost       Ubuntu-19

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

^G Get Help  ^O Write Out ^W Where Is  ^K Cut Text  ^J Justify   ^C Cur Pos
^X Exit      ^R Read File ^\ Replace   ^U Uncut Text^T To Spell  ^_ Go To Line

When changes have been completed, press Ctrl+x and then yes to save file.


Finally you have seen how easy to change hostname in Linux (Ubuntu) Operating System. Now you can change computer name as your requirement without any restriction .

If you have any question related this article and Please write in comment box. Me and other expert person will give you reply.


If Appreciate My Work, You should consider:

Leave a Comment

Skip to toolbar