Change Hostname on Ubuntu 20.04 {via GUI or Terminal}

Introduction

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

You may decide to change your computer’s hostname for several reasons. For example, no two computers on a network can have the same host name, and if you are in this situation, you will have to change the host name to avoid a network conflict.

In this tutorial, you will learn how to change a hostname in Ubuntu 20.04 using the Linux command line or GUI

.

prerequisites

Ubuntu 20.04

    installed

  • An account with sudo privileges
  • Command-line access for non-GUI methods How to
  • Check Current Hostname in Ubuntu

  • 20.04

To check the current hostname

of your Ubuntu system, use one of the two available commands

.

  • The hostname command displays only the host name itself.

The

  • other command, hostnamectl, displays additional information about the computer system

.

The Static Host Name line displays the host name of the computer.

Temporarily Change Hostname in

Ubuntu 20.04

Use the hostname command to

make a temporary change to the host name of the computer

.

In the terminal, type the following, replacing new-hostname with the name you choose: sudo hostname new-hostname

If successful, this step will not provide any results. To confirm the result

of the process, check the hostname of the current system: Change hostname in

Ubuntu 20.04 (no

need to reboot) If you want to permanently change the hostname without restarting the computer, use the hostnamectl command. Step 1: Use set-hostname to change the host name

Type the following

command: hostnamectl set-hostname new-hostname Use

your own choice of hostname instead of new-hostname.

Step 2: Use

hostnamectl to confirm the change Like the hostname command, if successful,

hostnamectl set-hostname

produces no output.

Therefore, use hostnamectl to verify the result.

Step 3: Change the pretty hostname (optional)

A “

pretty” hostname is the hostname presented to the user, not to another computer on a network. A computer system identifies another computer only by its static host name.

To change the “pretty” hostname of a machine, use the same hostnamectl command with the -pretty option: hostnamectl set-hostname “new-hostname” -pretty

Replace new-hostname with your own UTF-8 value

.

After checking the result with hostnamectl, you will notice an additional line in the output, which lists the “nice” hostname of the computer. Change Hostname in Ubuntu 20.04

Alternative Method (Reboot Required)

Another way to permanently change the hostname

is by editing two configuration files

: /etc/hostname/etc/hosts

The changes take effect immediately after the system reboots

.

Step 1: Open /etc/hostname and change the hostname

Edit the file with a text editor of your choice. In this example, we will use the Vim editor:

sudo vi /etc/hostname

The /etc/hostname file contains only the current hostname. Replace it with your new option.

Save the file and exit.

Step 2: Open

/etc/hosts and change the hostname

Now edit

the /etc/hosts file in the same way. sudo vi /etc/hosts

The /etc/hosts file maps host names to IP addresses. Find the hostname you want to change and simply replace it with your new option.

Save the edits and exit.

Step 3

: Restart the system

Restart your computer to apply the changes

: sudo systemctl restart Change hostname

in Ubuntu 20.04 Using

GUI

The Ubuntu GUI also provides a way to edit the system hostname:

1. First, navigate to Settings > About.

2. Now, look for the Device Name field.

3 Clicking the Device Name field opens the Rename Device dialog box.

4. In the Rename Device dialog box

, replace the current hostname with a new one and confirm your choice by clicking the Rename button. This action permanently changes the host name.

Conclusion

This article introduced three methods wherein you can change the hostname on your Ubuntu 20.04 machine, using the command line or GUI. All methods are simple and straightforward, so you can choose the one that best suits your use case.