×



A hostname is a user-generated custom name which identifies a computer system in a network. In Ubuntu 20.04, users assign a hostname to the machine during OS setup.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Linux System queries.

In this context, we shall look into how to change hostname on Ubuntu 18.04 system.


How to Change Hostname on Ubuntu ?

Before proceeding with this Configuration procedure, ensure that you are using a user with sudo privileges. Using a hostname you can identifies a system on a network. Ensure that each machine have different hostname on a same network.


To Get Current Hostname,

First of all you need to check current hostname. You can view the current hostname by running the below command:

$ hostnamectl
  Static hostname: local.linuxapt
        Icon name: computer-laptop
          Chassis: laptop
       Machine ID: 39bb66809520461594c31b34a4829d7b
          Boot ID: 5b6b4bc9e7584e4ba62313eeaab9dd61
 Operating System: Ubuntu 18.04.2 LTS
           Kernel: Linux 4.15.0-46-generic
     Architecture: x86-64

Here, you can see that the current hostname is local.linuxapt.


How to change the Hostname using hostnamectl ?

We can change hostname using multiple methods. First one is using hostnamectl command. Following is the basic syntax to change hostname using hostnamectl :

$ sudo hostnamectl set-hostname NEW_HOST_NAME

Below is the command to change hostname:

$ sudo hostnamectl set-hostname server.linuxapt.com

As you can see here, we have changed the hostname from local.linuxapt to server.linuxapt.com using hostnamectl command. 

Now the hostname is server.linuxapt.com for Ubuntu machine, you can check it again using hostnamectl command.


How to Change the Hostname by Edit /etc/hosts file ?

Another method to change hostname is to modify /etc/hosts file manually.

i. So open /etc/hosts file using your favorite text editor:

$ sudo nano /etc/hosts

Here, find the hostname and change as per you choice at line which start with 127.0.0.1

ii. Save and close file.

You should restart your system to get changes in effect.


How to Verify Hostname ?

After changing hostname using second method, you can again check hostname using hostnamectl command:

hostnamectl 

Now it will show output with new hostname as below:

Static hostname: server.linuxapt.com
        Icon name: computer-laptop
          Chassis: laptop
       Machine ID: 39bb66809520461594c31b34a4829d7b
          Boot ID: 5b6b4bc9e7584e4ba62313eeaab9dd61
 Operating System: Ubuntu 18.04.2 LTS
           Kernel: Linux 4.15.0-46-generic
     Architecture: x86-64

That's how to go about it. As you can see above the hostname is successfully changed from local.linuxapt to server.linuxapt.com.


[Need help in fixing Ubuntu Linux System? We can help you. ]


Conclusion


More Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on IbmiMedia.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com