Vol. I · No. 46The command line sectionSat, 10 Oct 2026
Linux · system information

hostname

what is this machine called

hostname 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.

Prints
The host name
as in the prompt
Addresses
hostname -I
all of them, on one line
Full name
hostname -f
with the domain
To change it
hostnamectl
so it survives a reboot

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.

user@netflow — bashhostname
$ hostname
1netflow
2$ hostname -I
192.168.1.42 10.8.0.2
3$ hostname -f
netflow.lab.example
4$ sudo hostnamectl set-hostname web01
Illustrative session · names, sizes and dates are examples, and every address is from a documentation or private range
Reading the output

What the numbered lines are telling you

1
The short name

The same name that appears after the @ in the prompt.

2
Every address the machine has

Two here: one on the local network and one on a VPN. The loopback address is left out.

3
The fully qualified name

The host name with its DNS domain, where one is configured.

4
Renaming the machine

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.

hostnamectl

Shows the name together with the OS, kernel and hardware.

cat /etc/hostname

The file the name is read from at boot.

hostname -i

The 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.

Names give things away

db-prod-01 and vpn-gateway advertise their role to anyone who sees them in a banner, a certificate or a DNS record.

Check before you act

Running a destructive command on production instead of the test server is a classic accident. Look at the prompt, or run hostname, first.

Keep /etc/hosts in step

If the machine’s own name does not resolve, sudo becomes slow and some services fail. After renaming, update the entry in /etc/hosts.

Protocols it shows

DNSIPv4

Read alongside