Thursday, November 27, 2014

Hostname Command Examples in Linux



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 "linux", then the hostname of the computer is "linux.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
linux.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

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
linux

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

No comments:

Post a Comment