×


Change Hostname on Ubuntu 18.04 - How to do it ?

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 Ibmi Media, 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

This article covers how to change the hostname on Ubuntu 18.04 system using multiple methods. HostName is also referred to as the computer name of your system. It is used to identify the device in various forms of electronic communication in the computer network. Hostname helps you to access local web pages and other authorized data on your system.

The host name or computer name is usually at system startup in /etc/hostname file.


How to change the computer name on Ubuntu Linux ?

1. Type the following command to edit /etc/hostname using nano or vi text editor:

$ sudo nano /etc/hostname

Delete the old name and setup new name.

2. Next Edit the /etc/hosts file:

$ sudo nano /etc/hosts

Replace any occurrence of the existing computer name with your new one.

3. Reboot the system to changes take effect:

$ sudo reboot