> ## Content Index
> Fetch the complete content index at: https://snubmonkey.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# How to Change or Set Hostname on Ubuntu Server.
- URL: https://snubmonkey.com/how-to-change-hostname-on-ubuntu-server/
- Published: 2021-04-02T09:01:00.000Z
- Updated: 2025-04-16T22:54:21.000Z
- Description: The hostname is what a device is called on a network. The hostname is used to distinguish devices within a local network. In addition, computers can be found by others through the hostname, which enables data exchange within a network.
- Author: Kenzo Kylo
- Tags: how to 🪄, linux 🐧

In Unix-like operating systems, users assign a hostname to the machine during the OS setup. You may decide to change your computer's hostname for various reasons. For instance, no two computers on a network can have the same hostname, and if you find yourself in this situation, you will have to change your hostname. In this article, you will learn how to set or change a hostname on an Ubuntu server 20.04 using the Linux command line.

##   
Check your current Hostname
  
  
To check the current hostname of your Ubuntu system, use one of two available commands.  
  
The **`hostname`** command displays only the hostname itself.

```zsh
$ hostname
batman
```

The other command, **`hostnamectl`**, displays additional information about your computer system.

```zsh
$ hostname
   Static hostname: batman
         Icon name: computer-vm
           Chassis: vm
        Machine ID: c1cbeec7609843cdae2d7e8b4d359513
           Boot ID: d66ebd50543d405481332a5506a5dbc5
    Virtualization: oracle
  Operating System: Ubuntu 20.04.2 LTS
            Kernel: Linux 5.4.0-67-generic
      Architecture: x86-64
```

As you can see the **`Static hostname`** line displays your machine’s hostname.

##   
  
Change or Set Hostname (Reboot Required)
  
  
A way to permanently change the hostname is by editing those two configuration files:

- */etc/hostname*

```zsh
$ sudo nano /etc/hostname

```

Delete the old name and setup a new one.

- */etc/hosts*

```zsh
$ sudo nano /etc/hosts

```

The file */etc/hosts* maps hostnames to IP addresses. Look for any occurrence of the existing computer name and simply replace it with your new choice.

This changes take effect immediately after system reboot.

```zsh
$ sudo reboot

```

## Change or Set Hostname (No Reboot Required)
  
  
To make a temporary change to your computer’s hostname without rebooting your computer use the **`hostnamectl`** command.

```zsh
$ sudo hostnamectl set-hostname new-hostname

```

Of course, you will need to replace **new-hostname** with your own hostname choice.   
Use **`hostnamectl`** to Confirm the Change.

## Change or set the Pretty Hostname (Optional & Bonus)  
  
  
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 hostname.  
  
To change a machine’s “pretty” hostname, use the **`hostnamectl`** command with the **`--pretty`** option:

```zsh
$ sudo hostnamectl set-hostname new-hostname --pretty
```

Of course, you will need to replace **new-hostname** with your own hostname choice.   
  
  
After checking the result with **`hostnamectl`**, you should notice an additional line in the output, listing your computer’s "pretty" hostname.

```zsh
$ hostnamectl                                                              
   Static hostname: batman
   Pretty hostname: Mr. Snubmonkey
         Icon name: computer-vm
           Chassis: vm
        Machine ID: c1cbeec7609843cdae2d7e8b4d359513
           Boot ID: d66ebd50543d405481332a5506a5dbc5
    Virtualization: oracle
  Operating System: Ubuntu 20.04.2 LTS
            Kernel: Linux 5.4.0-67-generic
      Architecture: x86-64
```

The "pretty" hostname is stored in */etc/machine-info*. Updating this file is another way to perform this optional step.

  
That's it... you've learned something; how to Change or Set a hostname on Ubuntu Server using the Linux command line.