Hostname and Computer Identity
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:
|
|
To display only the static hostname:
|
|
Changing the hostname
To change the hostname, use the hostname operation of hostnamectl.
For example, to set the hostname to mocaccino-pc, run:
|
|
The change takes effect immediately. You do not need to reboot the system.
You can verify the new hostname with:
|
|
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:
|
|
To set a descriptive pretty hostname, run:
|
|
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:
|
|
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:
|
|
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:
|
|
You can also consult the Gentoo Handbook: