• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Change Hostname on Ubuntu 18.04

Written by Admin, Updated On May 7, 2019
hostname, ubuntu
How to change hostname on Ubuntu 18.04

The hostname is set when you are installing the Ubuntu operating system. If it is a virtual machine then it will assigned dynamically when instance created. In this guide, we will show you how to change hostname on Ubuntu 18.04 system.

Prerequisites#

Before you continue with tutorial, make sure that you are logged in with non-root user with sudo privileges.

Change Hostname on Ubuntu#

Using a hostname you can identifies a system on a network. Ensure that each machine have different hostname on a same network.

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.tecnstuff
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

In above output you can see that the current hostname is local.tecnstuff.

Changing 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.tecnstuff.net

As you can see here, we have changed the hostname from local.tecnstuff to server.tecnstuff.net using hostnamectl command. Now the hostname is server.tecnstuff.net for Ubuntu machine, you can check it again using hostnamectl command.

Change the Hostname by Edit /etc/hosts file#

Second method to change hostname is to modify /etc/hosts file manually. So open /etc/hosts file using your favorite text editor:

sudo nano /etc/hosts

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

Save and close file. You should restart your system to get changes in effect.

Verify Hostname#

After changing hostname using second method, you can again check hostname using hostnamectl command and now it will show output with new hostname as below:

  Static hostname: server.tecnstuff.net
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 all. As you can see above the hostname is successfully changed from local.tecnstuff to server.tecnstuff.net .

Conclusion#

Finally, you have learned how to change the hostname on Ubuntu 18.04 system using multiple methods.

If you are getting any issue to change hostname or have any suggestions you can leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Node.js and npm on Debian 9
Next Article   How to Set Up SSH Keys on CentOS 7

Related Posts

  • How to Change Hostname Debian 11

    How to Change Hostname on Debian 11

    February 3, 2023
  • How to Install and Use PHP Composer on Ubuntu 22.04

    How to Install Composer on Ubuntu 22.04

    January 31, 2023
  • How to Install Nginx on Ubuntu 22.04

    How to Install Nginx on Ubuntu 22.04

    January 28, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook