System
hostname
Show or set the system hostname.
hostnamesystemnetworkidentity
Additional Notes
hostname prints or sets the system hostname. The hostname identifies a machine in prompts, logs, local networks, and service discovery.
On systemd systems, hostnamectl is usually preferred for permanent hostname changes.
Syntax
hostname [options] [name]
Parameters
options: Flags that change howhostnamebehaves.'name': New hostname to set (optional).
Common Options
-f,--fqdn: Show fully qualified domain name when available.-s,--short: Show short hostname.-d,--domain: Show DNS domain name.-I: Show assigned IP addresses.-i: Show addresses for the hostname.
Examples
hostname
Print the current hostname.
hostname -s
Print short hostname.
hostname -I
Print IP addresses assigned to the host.
sudo hostname temporary-name
Set a temporary hostname until reboot or service override.
Practical Notes
- Use
hostnamectl set-hostname NAMEfor persistent changes on systemd. - Hostname changes can affect logs, prompts, monitoring, and local name resolution.
- Check
/etc/hostnameand/etc/hostson many distributions.