LinuxCommandLibrary

hostname

Display or set system hostname

TLDR

Show current host name

$ hostname
copy

Show the network address of the host name
$ hostname [[-i|--ip-addresses]]
copy

Show the FQDN (Fully Qualified Domain Name)
$ hostname [[-f|--fqdn]]
copy

Set current host name
$ hostname [new_hostname]
copy

SYNOPSIS

hostname [OPTION]... [HOSTNAME]

PARAMETERS

-a, --alias
    Display all aliases of the host.

-d, --domain
    Display the domain name.

-f, --fqdn, --long
    Display the fully qualified domain name (FQDN).

-i, --ip-address
    Display the IP address(es) of the host.

-I, --all-ip-addresses
    Display all IP addresses of the host.

-s, --short
    Display the short hostname.

-v, --verbose
    Be verbose.

-h, --help
    Display help text and exit.

-V, --version
    Display version information and exit.

HOSTNAME
    Set the hostname to HOSTNAME (requires root privileges).

DESCRIPTION

The hostname command is a fundamental utility in Linux used to display or modify the system's hostname. The hostname is a label assigned to a machine on a network, allowing it to be identified by a human-readable name rather than an IP address.

When used without arguments, hostname simply displays the current hostname. When provided with an argument, the command attempts to set the hostname to the specified value. Setting the hostname typically requires superuser privileges (root). The changes made by the hostname command might be temporary, persistent or permanent and it depends on the distribution settings.

The hostname is stored in various system files and configurations, depending on the Linux distribution. Commonly, it's found in /etc/hostname. It's also stored in memory during the system boot and can be set during boot time. Changes made via hostname may only affect the in-memory representation of the hostname. Distributions like Debian and derivatives might require manually editing the /etc/hostname file and restarting the hostname service or rebooting the system to persist changes permanently.

CAVEATS

Setting the hostname with the `hostname` command may not persist after a reboot. Persistent hostname configuration varies by distribution. Using hostname to set the hostname requires superuser/root privileges.
It is recommended to keep the hostname short and conform to DNS naming conventions.

HOSTNAME RESOLUTION

The system resolves hostnames to IP addresses through various mechanisms, including DNS, the /etc/hosts file, and network configuration. The hostname is used by applications to identify the local machine when making network connections.

NETWORK CONFIGURATION

Setting hostname correctly is crucial for proper network operation, especially in environments relying on DNS or other hostname-based services. It enables easier identification of machines within the network, which benefits network administration.

HISTORY

The hostname command has been a standard part of Unix-like operating systems for a very long time. Its primary purpose has always been to manage the system's hostname, a fundamental aspect of network identification. It has evolved to include more options for displaying different aspects of the hostname and associated network information.

SEE ALSO

Copied to clipboard