Thursday 31 December 2020

Hostname Command Examples in Unix / Linux

LPI Exam Prep, LPI Tutorial and Material, LPI Prep, LPI Learning, LPI Career, LPI Certification

Hostname is the name of the system or server you are logged into. The hostname can also refer to the sitename or computer name. As an example, if an organization domain name is "google.com" and a specific computer name in that doman is "unix-box", then the hostname of the computer is "unix-box.google.com".

The syntax of hostname command in unix or linux system is

hostname [options] [file]

The options of hostname command are:

-a : Prints the alisa name of the host if created any.

-d : prints the domain name

-i : prints the ip address of the host

-s : prints the shortname of the host.

-v : verbose data

-V : version information

-h : help about hostname command

Hostname Command Examples:

1. Print the hostname of the system The basic functionality of the hostname command is to display the name of the system on the terminal. Just type the hostname on the unix terminal and press enter to print the hostname.

> hostname

unix-box.google.com

2. Ip address of the computer You can find the ip address of the computer by using the -i option with hostname command.

> hostname -i

125.20.223.69

LPI Exam Prep, LPI Tutorial and Material, LPI Prep, LPI Learning, LPI Career, LPI Certification
3. Print the domain name To know the domain name where the computer resides, use the -d option with hostname command.

> hostname -d

google.com

4. Short hostname By default the hostname command prints the complete name of the computer. You can print a short name by using the -s option. This prints the name upto the first dot in the full hostname.

> hostname -s

unix-box

5. Getting help To get help about the hostanme command either use the man command or the -h option with hostname command.

> man hostname

> hostname -h

Related Posts

0 comments:

Post a Comment