Identify the server before making changes
Check the node name alongside the user identity. These are independent properties.
Reads or temporarily sets the host name; selected options report FQDNs and addresses.
hostname
current name
hostname -s
short name
hostname -f
resolved FQDN
hostname -i
name-derived addresses
hostname -I
interface addresses
hostname --version
utility version
Plain hostname prints the current node name. This identifies a machine, not a
user, and need not be a fully qualified DNS name. The utility can also change the
name, so adding an operand changes the purpose of the invocation.
A fully qualified domain name, or FQDN, depends on system name resolution. The source can be /etc/hosts or DNS according to the resolver configuration. Adding a dotted name does not automatically create a valid DNS record.
Option case matters: -i resolves addresses for the host name, whereas -I enumerates interface addresses without relying on resolution of that name. The -I result excludes loopback and IPv6 link-local addresses; order is not guaranteed. Neither option means “public IP”.
-F reads a name from a file and changes state. A plain hostname operand also sets
the current node name. For persistent Ubuntu configuration, use hostnamectl and
check local name resolution.
| Option | What it does | Example |
|---|---|---|
-a --alias |
Aliases obtained through name resolution. | hostname -a |
-f --fqdn |
The resolved fully qualified host name. | hostname -f |
-i --ip-address |
Addresses obtained by resolving the current host name. | hostname -i |
-I --all-ip-addresses |
Interface addresses excluding loopback and IPv6 link-local. | hostname -I |
-s --short |
The short name before the first dot. | hostname -s |
-A --all-fqdns |
Resolved FQDNs for interface addresses, not a single canonical identity. | hostname -A |
-b --boot |
Use a default name if none is available; a setting mode. dangerous | hostname -b |
-d --domain |
The DNS domain from the resolved FQDN, not the resolver search list. | hostname -d |
--long |
Synonym for --fqdn. | hostname --long |
-F --file file |
Read a name from a file and set it. dangerous | hostname -F ./hostname.txt |
-y --yp |
The NIS/YP domain, not the DNS domain. | hostname -y |
--nis |
Synonym for --yp. | hostname --nis |
-V --version |
Installed utility version. | hostname -V |
-h --help |
Display help and exit. | hostname -h |
Nothing found. Try a shorter query.
Check the node name alongside the user identity. These are independent properties.
getent queries the configured system name sources. A result does not prove that
DNS supplied it.
Different name and interface configuration can legitimately produce different results. Inspect ip for details.
Check how the system resolver handles the current name. Do not rename the machine merely to suppress the error.
A machine may have several interfaces and addresses. Do not treat the first result as universally correct; match it to the intended network.
A temporary change does not replace persistent configuration. Inspect hostnamectl
and /etc/hostname; external provisioning can also change the name.
Danger.
hostname new-nameandhostname -F filechange the name when privileges permit. This can disrupt expected resolution and dependent services. The cheat sheet above only reads information. Do not rename a machine to “fix DNS” without diagnosing the cause.
hostnamectl — persistent naming with systemd.
dns-resolv — name-resolution sources.
ip — per-interface addresses.
uname — node identity among system information.
Found an inaccuracy? Report an error in the article