hostname
what is this machine calledhostname prints the system’s name — the one in your shell prompt. With -I it prints the machine’s IP addresses, which is the quickest way to answer "what is my address?"
With several terminals open, the host name is how you know which machine you are about to change.
At the terminal
Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.
What the numbered lines are telling you
The same name that appears after the @ in the prompt.
Two here: one on the local network and one on a VPN. The loopback address is left out.
The host name with its DNS domain, where one is configured.
hostnamectl writes the new name to /etc/hostname, so it is kept after a reboot. Open a new shell to see it in the prompt.
Switches
A switch changes how the command behaves. These are the ones used day to day; man hostname lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.
-I- Print all the IP addresses of the host.
-f- Print the fully qualified domain name.
-s- Print the short name, cut at the first dot.
-d- Print the DNS domain name.
-i- Print the address the host name resolves to.
Variations worth knowing
The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.
hostnamectlShows the name together with the OS, kernel and hardware.
cat /etc/hostnameThe file the name is read from at boot.
hostname -iThe address the host name itself resolves to.
getent hosts $(hostname)Checks how the machine resolves its own name.
In cybersecurity
A host name tells an outsider what a machine is for.
db-prod-01 and vpn-gateway advertise their role to anyone who sees them in a banner, a certificate or a DNS record.
Running a destructive command on production instead of the test server is a classic accident. Look at the prompt, or run hostname, first.
If the machine’s own name does not resolve, sudo becomes slow and some services fail. After renaming, update the entry in /etc/hosts.