To view the host name for a Linux or OS X system you are logged into, you can use the uname command with the
-n
option. On a Linux system, you can also use
--nodename
in lieu of -n
, but
--nodename
won't work on OS X. If the host name has not been set,
you will see localhost.localdomain
displayed.
$ uname --nodename localhost.localdomain
You can also use the hostname command on a Linux or OS X system to show or set the host name. To show the host name, issue the command without any parameters
$ hostname localhost.localdomain
On some versions of Linux, e.g., CentOS and Ubuntu, you can also view the host name using the sysctl command; it won't work on OS X, however.
[ More Info ]