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:
- cpp command in Linux with Examples
- id command in Linux with examples
- top command in Linux with Examples
- pwd command in Linux with Examples
- cal command in Linux with Examples
- env command in Linux with Examples
- mv command in Linux with examples
- tty command in Linux with examples
- dir command in Linux with examples
- df command in Linux with Examples
- du command in Linux with examples
- cp command in Linux with examples
- let command in Linux with Examples
- scp command in Linux with Examples
- cmp 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.



