hostname Command

Purpose

Displays the name of the current host system.

Syntax

hostname [ { -a | -A | -d | -f | —h | -i | --all-ip-addresses | -s | —V | -y } ] [ HostName ]

Description

The hostname command displays the name of the current host system as returned by the gethostname subroutine. If the hostname command is used without any option, it prints the short hostname. If a new HostName is specified, it sets the hostname. However, only users with root user authority can set the hostname.

Flags

Table 1. Flags
Item Description
-a or --alias Displays the alias name of the host.
-A or --all-fqdns Displays all the Fully Qualified Domain (FQDN) names. This option is useful when multiple DNS entries exist.
-d or --domain Displays the domain name
-f, --fqdn, or --long Display the FQDN.
-h or --help Displays help about the hostname command.
-i or --ip-address Displays the IP addresses of the host.
--all-ip-addresses Displays all the IP addresses of the host including IPv4 and IPv6 for all the interfaces.
-s or --short Displays the short hostname.
-V or --version Displays version information.
-y, --yp, or --nis Display the NIS or YP domain name.

Examples

  1. To display the short hostname of the current host system, enter the following command:
    hostname
    
    or
    
    hostname -s
  2. To display the FQDN of the current host system, enter the following command:
    hostname -f
  3. To display all the IP addresses of the host, enter the following command:
    hostname --all-ip-addresses
  4. To display all the FQDN if there are multiple DNS records, enter the following command:
    hostname -A