How to change hostname on Ubuntu 20.04 Focal Fossa Linux

In this tutorial you will learn how to permanently and without a reboot change a hostname on Ubuntu 20.04 Focal Fossa Linux.

In this tutorial you will learn:

  • How to change a hostname on Ubuntu Linux

How to change hostname on Ubuntu 20.04 Focal Fossa Linux

How to change hostname on Ubuntu 20.04 Focal Fossa Linux

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to change hostname on Ubuntu 20.04 step by step instructions

Changing the hostname on Ubuntu 20.04 is a rather simple process involving just few steps.

  1. First, check your current hostname. To do so use either hostnamectl or hostname command:
    $ hostname
    ubuntu
    

    Your output of the hostnamectl command may look similar to the one below:

    $ hostnamectl 
       Static hostname: ubuntu
             Icon name: computer-vm
               Chassis: vm
            Machine ID: 947a975389d14662b8543c6192fc9658
               Boot ID: f9dcef4c25964e3ca7ebcf21e7400a9f
        Virtualization: oracle
      Operating System: Ubuntu Focal Fossa
                Kernel: Linux 5.4.0-9-generic
          Architecture: x86-64
    

    In either case the current hostname of our system is ubuntu.



  2. Change your hostname to eg. linuxconfig or any other desired hostname by using the hostnamectl command:
    $ sudo hostnamectl set-hostname linuxconfig
    

    The above command change the hostname of our Ubuntu system to linuxconfig.

    NOTE
    Upon changing your hostname using the hostnamectl command no system reboot is required to apply the hostname change.
  3. Next, edit the /etc/hosts file to reflect the change by executing the sudoedit /etc/hosts. For example change:

    FROM:

    127.0.0.1 localhost
    127.0.1.1 ubuntu
    

    TO:

    127.0.0.1 localhost
    127.0.1.1 linuxconfig
    
  4. Execute the hostnamectl command to confirm the hostname change:
    $ hostnamectl 
       Static hostname: linuxconfig
             Icon name: computer-vm
               Chassis: vm
            Machine ID: 947a975389d14662b8543c6192fc9658
               Boot ID: f9dcef4c25964e3ca7ebcf21e7400a9f
        Virtualization: oracle
      Operating System: Ubuntu Focal Fossa
                Kernel: Linux 5.4.0-9-generic
          Architecture: x86-64