Hostname and Computer Identity

Configure the hostname of your MocaccinoOS computer using hostnamectl.

Hostname and Computer Identity

Every computer on a network has a hostname. It is used to identify the system locally and on the network.

MocaccinoOS uses systemd, which provides the hostnamectl command to view and configure the system hostname.

Checking the current hostname

To display the current hostname and related information, run:

1
$ hostnamectl

To display only the static hostname:

1
$ hostnamectl --static

Changing the hostname

To change the hostname, use the hostname operation of hostnamectl.

For example, to set the hostname to mocaccino-pc, run:

1
$ sudo hostnamectl hostname mocaccino-pc

The change takes effect immediately. You do not need to reboot the system.

You can verify the new hostname with:

1
$ hostnamectl

Choose a hostname that is easy to recognize on your local network. For compatibility, use lowercase letters, numbers and hyphens. Avoid spaces and do not begin or end the hostname with a hyphen.

Static, transient and pretty hostnames

Systemd distinguishes between three types of hostname:

  • Static hostname: The persistent system hostname stored in /etc/hostname.
  • Transient hostname: A temporary hostname that may be assigned by network configuration services, such as DHCP.
  • Pretty hostname: A descriptive, human-friendly name that may contain spaces and special characters.

To view each value, use:

1
2
3
$ hostnamectl --static
$ hostnamectl --transient
$ hostnamectl --pretty

To set a descriptive pretty hostname, run:

1
$ sudo hostnamectl --pretty set-hostname "Mocaccino Desktop"

The pretty hostname is intended for display purposes. The static hostname remains the system’s network identifier.

The /etc/hostname file

The static hostname is stored in /etc/hostname. When using hostnamectl, systemd updates this file automatically.

You can inspect its contents with:

1
$ cat /etc/hostname

Normally, you should use hostnamectl to change the hostname instead of editing this file directly.

The /etc/hosts file

The /etc/hosts file maps hostnames to IP addresses. It can be used to define local names for computers and other devices that are not resolved by your network’s DNS server.

For example:

1
2
3
4
127.0.0.1    localhost
::1          localhost
192.168.1.10 nas.home.lan nas
192.168.1.20 printer.home.lan printer

The addresses above are examples; replace them with the addresses and names used on your network.

On MocaccinoOS, which uses systemd, changing the hostname with hostnamectl is normally sufficient. You do not need to add the hostname to /etc/hosts just to set the system hostname. Only add entries when you need local name-to-address mappings, and take care not to remove existing entries.

Additional information

For more information about hostnamectl, consult its manual page:

1
$ man hostnamectl

You can also consult the Gentoo Handbook:

Last modified November 29, 2026: Update SFTP (f553589)