# hostnamectl — Manage the System Hostname on systemd

> View and set the hostname on systemd Linux: static, transient and pretty names plus chassis, deployment and machine metadata.

Source: https://www.jpkc.com/db/en/cheatsheets/shell-system/hostnamectl/

<!-- PROSE:intro -->
hostnamectl is the systemd tool for viewing and changing your Linux machine's hostname from one place, instead of juggling `/etc/hostname` and the legacy `hostname` command. systemd tracks three layers: the **static** hostname (persistent, stored in `/etc/hostname`), the **transient** one (kept by the kernel at runtime) and the **pretty** name (free-form, with spaces and Unicode allowed). On top of that you can record metadata such as the chassis type, icon, deployment environment and physical location. This guide covers the commands you actually reach for on servers and desktops.
<!-- PROSE:intro:end -->

## Status & Info

`hostnamectl` — Show current hostname and system info.

```bash
hostnamectl
```

`hostnamectl status` — Show detailed hostname status (same as no args).

```bash
hostnamectl status
```

`hostnamectl hostname` — Show only the current hostname.

```bash
hostnamectl hostname
```

## Set Hostname

`hostnamectl set-hostname '<name>'` — Set the static hostname (persists across reboots).

```bash
sudo hostnamectl set-hostname webserver01
```

`hostnamectl set-hostname '<name>' --static` — Set only the static hostname.

```bash
sudo hostnamectl set-hostname webserver01 --static
```

`hostnamectl set-hostname '<name>' --pretty` — Set the pretty hostname (free-form, can include spaces).

```bash
sudo hostnamectl set-hostname 'Web Server 01 (Production)' --pretty
```

`hostnamectl set-hostname '<name>' --transient` — Set the transient hostname (lost on reboot).

```bash
sudo hostnamectl set-hostname temp-hostname --transient
```

## Machine Info

`hostnamectl set-icon-name '<name>'` — Set the machine icon name.

```bash
sudo hostnamectl set-icon-name computer-server
```

`hostnamectl set-chassis '<type>'` — Set the chassis type (desktop, laptop, server, vm, container).

```bash
sudo hostnamectl set-chassis server
```

`hostnamectl set-deployment '<env>'` — Set the deployment environment.

```bash
sudo hostnamectl set-deployment production
```

`hostnamectl set-location '<location>'` — Set the location description.

```bash
sudo hostnamectl set-location 'Frankfurt DC, Rack 42'
```

<!-- PROSE:outro -->
## Conclusion

hostnamectl replaces hand-editing `/etc/hostname` with one consistent command and cleanly separates the static, transient and pretty hostnames – for everyday use you mostly need plain `hostnamectl` to read and `set-hostname` to change. Write actions require `sudo`, and the tool exists only on systemd systems (it is absent on other init systems and in some minimal containers). Keep in mind, too, that on production servers a hostname is rarely just cosmetic – it shows up in logs, monitoring, TLS certificates and cluster membership. A change can therefore have knock-on effects; plan it deliberately on running systems and recheck dependent services afterwards.

## Further Reading

- [Arch Wiki: Hostname](https://wiki.archlinux.org/title/Hostname) – concise explanation of the hostname layers and how they are configured
- [systemd project site](https://systemd.io/) – official documentation for systemd and its tooling
<!-- PROSE:outro:end -->

## Related Commands

- [timedatectl](https://www.jpkc.com/db/en/cheatsheets/shell-system/timedatectl/) – manage system time, time zone and NTP synchronisation under systemd
- [systemctl](https://www.jpkc.com/db/en/cheatsheets/shell-system/systemctl/) – control and query systemd services and units
- [uname](https://www.jpkc.com/db/en/cheatsheets/shell-system/uname/) – print kernel and system information

