A host name is a name that is assigned to a host (i.e., a computer connected to the network) that uniquely identifies it on a network and thus allows it to be addressed without using its full IP address. Domain names are user-friendly substitutes for numeric IP addresses.
The basic syntax for the hostname command is
When used without any options or arguments (i.e., input data), hostname displays the current host and domain names of the local machine (i.e., the computer that is currently being used). The default host and domain name is typically localhost.localdomain.
When a name is provided as an argument, it becomes the new host name. A change in the host name can only be performed by the root (i.e., administrative) account, which can be accessed using the su (i.e., substitute user) command. For example, to change the host name to computer_01, the following would be used:
The -F option changes the host and domain names to that written in a plain text file whose name is provided after this option as an argument. Comments (i.e., lines starting with a pound sign) in the file are ignored. Thus, for example, if a file named name_1 were created that contained a line that consisted of morgan.localdomain, then following would change the hostname to morgan.localdomain:
The -s option displays the short host name, which is the part of the name to the left of the first dot (e.g., localhost or morgan in the above examples) i.e.,
Likewise, the -d option displays only the domain name, i.e., the section to the right of the final dot (localdomain in the above examples). The -a option displays any aliases (i.e., substitute names) that are used for the host name. The -i option displays the IP address(es) of the host, which by default is 127.0.0.1.
The -v (verbose) option provides additional information. The -V (upper case V) option displays version information, and the -h option displays a brief help message.
Created December 20, 2005.