CompTIA Certifications

CompTIA Network+ 2009 Domain 5: Network Tools

Hostname Networking Utility

On the Windows system, hostname simply prints out the hostname of the machine you are using. If you open a command prompt and type hostname you will see it return the hostname.

On Unix, Linux, and Mac OS X systems, hostname is much more powerful. You could use it to change the hostname of the machine, however, that typically occurs elsewhere. If you type in hostname on a Unix-like system, it will also display the hostname of the machine you are using, but there are other options beneath the surface:

root@thatcommunity [/home]# hostname -?
Usage: hostname [-v] {hostname|-F file}      set hostname (from file)
 domainname [-v] {nisdomain|-F file}   set NIS domainname (from file)
 hostname [-v] [-d|-f|-s|-a|-i|-y|-n]  display formatted name
 hostname [-v]                         display hostname

 hostname -V|--version|-h|--help       print info and exit

 dnsdomainname=hostname -d, {yp,nis,}domainname=hostname -y

 -s, --short           short host name
 -a, --alias           alias names
 -i, --ip-address      addresses for the hostname
 -f, --fqdn, --long    long host name (FQDN)
 -d, --domain          DNS domain name
 -y, --yp, --nis       NIS/YP domainname
 -F, --file            read hostname or NIS domainname from given file

 This command can read or set the hostname or the NIS domainname. You can
 also read the DNS domain or the FQDN (fully qualified domain name).
 Unless you are using bind or NIS for host lookups you can change the
 FQDN (Fully Qualified Domain Name) and the DNS domain name (which is
 part of the FQDN) in the /etc/hosts file.

As you can see, you can set the hostname using this utility.