How to Change Hostname (Computer Name) on Ubuntu & Debian

Channel: Linux
Abstract: how can you change the hostname of your Ubuntuyou need to set computer hostname to webhost1. hostnamectl set-hostname webhost1

Brief: This tutorial will show you to how to find current hostname of the system. Also, how can you change the hostname of your Ubuntu, Debian and LinuxMint systems?

Change Hostname using Hostnamectl

The latest operating systems (Eg: Ubuntu 18.04, 16.04, Debian 9/8) running with systemd uses hostnamectl command to manage computer hostname.

You can change the hostname of Linux system using the following command. For example, you need to set computer hostname to webhost1.

hostnamectl set-hostname webhost1

This will update /etc/hostname file on your system and load in the current environment. But you still need hostname binding with localhost IP.

Edit /etc/hosts file to bind new hostname with localhost IP address.

127.0.1.1  webhost1

Now, Execute the below command to find current hostname set for your system.

hostnamectl 

   Static hostname: webhost1
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 844c6ba3394d4646bd27ba204be67f27
           Boot ID: 5030cf55956a4c32ad3d6b7f391a3c77
    Virtualization: xen
  Operating System: Ubuntu 16.04.3 LTS
            Kernel: Linux 4.4.0-1049-aws
      Architecture: x86-64
Change Hostname Manually

You also use older way to change the hostname of the system manually by editing configuration files directly. To change hostname first edit /etc/hostname file and write your hostname there.

/etc/hostname:

webhost1

After editing the file, you can also set the hostname for the current session to avoid system reboot.

hostname webhost1

After that edit /etc/hosts file to bind new hostname with localhost IP address.

127.0.1.1  webhost1

Ref From: tecadmin

Related articles