Syntax of the `hostname` command in Linux

hostname -[option] [file]

Example: We obtain the system hostname by just typing the hostname without any attributes.  

hostname

Options           Description Syntax
-a

This option is used to get the alias name of the host system (if any). It will return an empty line if no alias name is set. This option enumerates all configured addresses on all network interfaces. 

hostname -a
-A

This option is used to get all FQDNs (Fully Qualified Domain Name) of the host system. It enumerates all configured addresses on all network interfaces. An output may display the same entries repetitively.

hostname -A
-b

Used to always set a hostname. Default name is used if none specified.

hostname -b
-d 

 This option is used to get the Domain if local domains are set. It will not return anything (not even a blank line) if no local domain is set.

hostname -d
-f 

This option is used to get the Fully Qualified Domain Name (FQDN). It contains short hostname and DNS domain name.

hostname -f
-F 

This option is used to set the hostname specified in a file. Can be performed by the superuser(root) only.

sudo hostname -F filename
-i

This option is used to get the IP (network) addresses. This option works only if the hostname is resolvable.

hostname -i
-I

This option is used to get all IP(network) addresses. The option doesn’t depend on resolvability of hostname.

hostname -I
-s

 This option is used to get the hostname in short. The short hostname is the section of hostname before the first period/dot(.). If the hostname has no period, the full hostname is displayed.

hostname -s
-V

Gives version number as output.

hostname -V

hostname command in Linux with examples

hostname command in Linux is used to obtain the DNS (Domain Name System) name and set the system’s hostname or NIS (Network Information System) domain name. A hostname is a name given to a computer and attached to the network. Its main purpose is to uniquely identify over a network.

Similar Reads

Syntax of the `hostname` command in Linux

hostname -[option] [file]...

Outputs of Options available in `hostname` command

1) `-a` Option in `hostname` command in Linux...

Conclusion

This command `hostname` in Linux seems so simple but at the same time it is a very powerful command that allows users to view or set the hostname of the system. It is important for users to know the `hostname` command to manage their Linux system effectively. One can easily understand by this article, as we have discussed many options and also their output, options like `-a`, `-A`, `-b`, `-d`, `-f`, `-F`, `-i`, `-I`, `-s` and `-V`....