The host name (set and displayed by the
hostname command, and typically stored in
/etc/hostname) is used by local applications. It is not known by other machines, and cannot be used to contact the host. The host name typically appears in shell prompts, and various applications might use it for logging purposes, for example by version control software when you make a commit.
There is no technical connection between the host name and any name that other machines may use to designate your machine. The DNS is what is normally used to name a machine in an Internet context (or more precisely, a network interface). It is a good idea if your host name is identical to the first component of the DNS name of the network interface of your machine that most of the world sees. For example, if your server is connected to the rest of the world through the
eth0 Ethernet interface, and the IP address of
eth0 has the name
foo.example.com, it is a good idea to choose
foo as your host name. If you do so,
foo.example.com is often called the FQDN (fully qualified domain name) of your machine. But you are free to leave them mismatched; a discrepancy can be confusing to the administrator, but doesn't matter to the software.
The host name may be used by some network protocols to identify the host. If so, it has to be sent by a local process running on the host. For example, in some setups, a DHCP client sends the hostname to the DHCP server to obtain an IP address; the DHCP server may use the claimed host name to decide which IP address to attribute to the client. In such setups, it is mandatory that the host name matches the DNS name.
Related: http://unix.stackexchange.com/questions/2387/why-is-my-hostname-different-in-emacsWhy is my hostname different in Emacs?; http://unix.stackexchange.com/questions/16890/how-to-make-a-machine-accessible-from-the-lan-using-its-hostnameHow to make a machine accessible from the LAN using its hostname