Where this file comes from:
Back in the days of ARPANet each computer had a file which mapped out the location of the other computers. As time went on, more & more computers were added to this list. With the list growing came the possibility for other machines to become out of date. This is where DNS came in. However, we can still make use of this file & method today!
On your Linux system, you'll find this file in /etc/hosts. The basic hosts file contain at least the following:
This allows you to communicate with 127.0.0.1 with the word 'localhost'. Go ahead & try it out for yourself!
Any entry within the hosts file with a number sign (#) is considered a comment.
# Local Host 127.0.0.1 localhost
The order to the hosts file is :
<IP Address> <host name> <alias>
So if you wanted to setup an internal webserver, & you wanted to access it using example, you could enter the following:
# Local Host 127.0.0.1 localhost # example web server 192.168.0.101 example
This will allow you to resolve example, to the given ip address.
# nslookup example Server: 192.168.0.2 Address: 192.168.0.2#53 Name: example Address: 192.168.0.101
The main drawback to using this method is you must 1st setup the ip addresses on each of the machines. Since DHCP stands the possibility of reassigning a new ip, this would cause your hosts file to become out of date.
For more information :