Home·Terminal commands

hostname

Processes and system

Usage

hostname [-f]

Prints or sets this machine's name; `hostname web01` only lasts until the next reboot, so make it permanent with `hostnamectl` on Linux or `scutil --set HostName` on macOS, and `-I` for every IP is Linux only.

Common flags

FlagMeaning
-sShort name only, up to the first dot.
-fFully qualified domain name (Linux).
-IAll IP addresses of this host, space separated. Linux only, capital i.
-iResolve the host name; depends on /etc/hosts, so it often prints 127.0.1.1 (Linux).
hostname <newname>Change it until the next reboot only.

Examples

hostname -f

The full name other machines see.

hostname -I

Every local IP without parsing ip or ifconfig output (Linux).

sudo hostnamectl set-hostname web01

The permanent change on systemd; macOS uses scutil --set HostName.

What is running and what is eating the machine. Identifying it comes before killing it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does hostname do?

Prints or sets this machine's name; `hostname web01` only lasts until the next reboot, so make it permanent with `hostnamectl` on Linux or `scutil --set HostName` on macOS, and `-I` for every IP is Linux only.

Q. How do I type it?

hostname [-f] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

5 are listed here; the full set is in man hostname. This command sits under Processes and system.

Related commands

man page: man hostname