# Ubuntu: Set Hostname

Here are steps to properly set the hostname of an Ubuntu server.

#### HostnameCtl

Get the current hostname with this:

```bash
hostnamectl
```

[![image.png](https://wiki.galaxydump.com/uploads/images/gallery/2025-05/scaled-1680-/Kl3ruPr1mCRlCusB-image.png)](https://wiki.galaxydump.com/uploads/images/gallery/2025-05/Kl3ruPr1mCRlCusB-image.png)

To set it, use this:

```bash
sudo hostnamectl set-hostname new-hostname (replace new-hostname)
```

Once set, confirm it with the previous command.

#### Hosts File

Now, you need to update the hostname in your hosts file, with this:

```
sudo nano /etc/hosts
```

The hosts file lists the hostname in the second entry: 127.0.1.1, like this:

[![image.png](https://wiki.galaxydump.com/uploads/images/gallery/2025-09/scaled-1680-/ZU6887t9afTNg3ft-image.png)](https://wiki.galaxydump.com/uploads/images/gallery/2025-09/ZU6887t9afTNg3ft-image.png)

Update the 127.0.1.1 entry with the correct hostname.

Save and close the hosts file after update.