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 which is given to a computer and it attached to the network. Its main purpose is to uniquely identify over a network.
Syntax :
hostname -[option] [file]
Example: We obtain the system hostname by just typing hostname without any attributes.

Options:
- -a : This option is used to get 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.
Syntax:
hostname -a
Example:
- -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 same entries repetitively.
Syntax :
hostname -A
Example:

- -b : Used to always set a hostname. Default name is used if none specified.
Syntax :
hostname -b
Example:

- -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.
Syntax :
hostname -d
Example :

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

- -F : This option is used to set the hostname specified in a file. Can be performed by the superuser(root) only.
Syntax:
sudo hostname -F filename
Example:

- -i option:This option is used to get the IP(network) addresses. This option works only if the hostname is resolvable.
Syntax:
hostname -i
Example:

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

- -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.
Syntax :
hostname -s
Example:

- -V : Gives version number as output.
Syntax:
hostname -V
Example:

Note: To set the hostname we can use the command given below:
sudo hostname NEW_HOSTNAME
Here, NEW_HOSTNAME is the new hostname the user wants to give.
Example:

Recommended Posts:
- tar command in Linux with examples
- sum command in Linux with Examples
- wc command in Linux with examples
- cd command in Linux with Examples
- cc command in Linux with Examples
- w command in Linux with Examples
- cut command in Linux with examples
- cmp Command in Linux with examples
- col command in Linux with Examples
- mv command in Linux with examples
- dc command in Linux with examples
- bc command in Linux with examples
- cvs command in Linux with Examples
- Cat command in Linux with examples
- arp command in Linux with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



