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
| Flag | Meaning |
|---|---|
| -s | Short name only, up to the first dot. |
| -f | Fully qualified domain name (Linux). |
| -I | All IP addresses of this host, space separated. Linux only, capital i. |
| -i | Resolve 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 -fThe full name other machines see.
hostname -IEvery local IP without parsing ip or ifconfig output (Linux).
sudo hostnamectl set-hostname web01The 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