Reference: http://wp.fungo.me/linux/what-the-hell-is-hostname.html
Hostname is the machine name, a variable in the kernel, can be temporarily modified or permanently modified
/etc/hosts The local DNS system, query the domain name will be first in this file inside the query, can not find the system DNS to find
So hostname and the hosts didn't have a half-penny relationship.
However, it is easy to cause confusion in the following situations:
Assuming that the domain name clickme.com is a DNS can not find the domain name, a machine hostname is precisely clickme.com, and on a machine want to access the native HTTP service through http://clickme.com, found inaccessible, and in/etc/ Add a row to the hosts
127.0.0.1 clickme.com
, found that can be accessed through the hostname, and thus mistakenly think that/etc/hosts and hostname have some kind of association (similar to let hostname into effect, etc.), is actually just a coincidence.
Linux under hostname and hosts