# Setting the Hostname of Linux Workstation or Server

A **hostname** is a human-friendly name given to a computer. It is a unique identifier that allows us to identify the machine in various network communications, making it easier to locate and manage devices.

Type:

```bash
hostname
```

To see where it is stored, type:

```bash
cat /etc/hostname
```

To get the hostname and additional information about your machine:

```bash
hostnamectl
```

To change the hostname, login as root user or use the `sudo` command:

```bash
sudo hostnamectl set-hostname my-private-workstation
```

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Restart your terminal window since the new settings will not show up.</div>
</div>

If you do not want to restart your terminal, you can force the current terminal to be changed by typing (assuming you use bash):

```bash
exec bash
```

Verify the hostname was changed:

```bash
cat /etc/hostname
```

Check the content of the `/cat/hosts` file

```bash
cat /etc/hosts
```

Even though the `hostnamectl` command allows us to set the new hostname, it does not update the `/etc/hosts` file. This is optional, but highly recommended.

To update the `/etc/hosts` file, use the `vim` command:

```bash
sudo vim /etc/hosts/
```

To ping this instance, run:

```bash
ping my-private-laptop
```

## References:

1. [Linux Crash Course - Setting the Hostname of your Linux Workstation or Server](https://www.youtube.com/watch?v=91dNq4C6260&list=PLT98CRl2KxKHKd_tH3ssq0HPrThx2hESW&index=69)
    
2. [How to Change Hostname on Ubuntu](https://phoenixnap.com/kb/ubuntu-20-04-change-hostname)
    
3. [How to configure a hostname on a Linux system](https://www.redhat.com/sysadmin/configure-hostname-linux)
