Changing Hostname in Ubuntu: A Step-by-Step Guide for Beginners

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, the 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 a time when you were installing Ubuntu.

But now, You don’t like that hostname by any reason and want to change it without restarting Ubuntu system. Yes you can change hostname easily by using the 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 the hostname.

Check hostname in Ubuntu Linux

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

vijay@Ubuntu-19:~$
vijay@Ubuntu-19:~$

In the 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 the following command to check the hostname

$hostname
$hostnamectl

vijay@Ubuntu-19:~$hostname
ubuntu19
vijay@Ubuntu-19:~$
vijay@Ubuntu-19:~$hostnamectl
   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:~$
vijay@Ubuntu-19:~$sudo cat /etc/hosts
[sudo] password for vijay: 
127.0.0.1	localhost
127.0.1.1	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
vijay@Ubuntu-19:~$

Change hostname in Ubuntu by using the hostname command

You have checked your hostname but you don’t 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
vijay@Ubuntu-19:~$hostname
LinuxOS
vijay@Ubuntu-19:~$

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

Change hostname in Ubuntu using hostnamectl

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

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

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

$sudo hostnamectl set-hostname UbuntuOS

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

Use GUI to Change hostname in Ubuntu Linux

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

The graphical interface is awesome and probably very easy to use.

The first step to check hostname, and Sorry, I will have to use the command line interface to check hostname.

vijay@Ubuntu-19:~$hostname
centos
vijay@Ubuntu-19:~$

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.

11-Go-to-setting

Step 2: Select about option from left side bar

12-click-on-detail

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

13-change-hostname-in-Linux-Ubuntu

Next After Change Hostname in Ubuntu

After change hostname you have done everything is not right. Here is one more step you have done to get identified in the 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 127.0.1.1 New-hostname

vijay@Ubuntu-19:~$sdo nano /etc/hosts
$127.0.0.1       localhost
127.0.1.1       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 the file.

Conclusion

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

If you have any question related to this article and Please write in the comment box. I and another expert person will give you a reply.

Cheers!

If you like our content, please consider buying us a coffee.
Thank you for your support!

Leave a Reply

Your email address will not be published. Required fields are marked *