Network and remote access

Command hostname

Show or change hostname

Linux · Bash examples · commands run on the selected server

When to use hostname

Use hostname to inspect the server's configured host identity while distinguishing it from public DNS and interface addresses. A displayed hostname alone does not prove that remote clients can resolve or reach that name.

Syntax

hostname [OPTIONS] [NAME]

Square brackets mark optional arguments; an ellipsis means repetition. Replace example file names, user names and server addresses with your own values.

Common options and arguments

No arguments
Show the current node name.
-f
Show the fully qualified domain name if name resolution is configured.
-I
Show interface addresses in Linux hostname.

Usage examples

Show server name

hostname

The system's current hostname is printed.

Check full name

hostname -f

The configured fully qualified name is resolved where the system configuration supports it.

Show assigned addresses

hostname -I

Configured host addresses are listed according to the Linux implementation.

Notes and limitations

  • hostname -f depends on DNS and local name configuration and can fail.
  • Changing the hostname usually requires privileges and may not persist after a reboot. Use your distribution's configuration tools for permanent changes.

Common questions and troubleshooting

Why does the fully qualified name lookup fail?

Local hostname configuration and name resolution may be inconsistent. Check the relevant hosts entries and DNS rather than assuming a network outage.

Is hostname -I my public internet address?

Not necessarily. It normally lists configured local interface addresses, which may be private or behind network address translation.

Further help

Options vary by version and distribution. Check the installed documentation with this command: man hostname.