Search This Blog

Tuesday, 4 December 2012

Hosts File? What is it? Why is it used?

In simple words, 
a hosts file contains mappings of IP addresses to host names.
For example, I would like to say, IP xxx.xxx.xxx.xx should be mapping to http://inspireinnovativelearning.blogspot.com

I keep adding new functionalities to my site. Later, I decide to host my web app on a different server, with a different IP. All I would do, is change my IP address in the hosts file and my web app would be up and running.

Most of the OS's have a hosts file. There's one for Linux, iOS, Unix, Windows Mobile, Android and so on. Complete list can be found in Wikipedia

This is how a host file looks
------------------------------------------------------------------------------------------------------------

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
127.0.0.1       localhost
# 127.0.0.1       ad.doubleclick.net #The IP is non-existent. It will block the site
------------------------------------------------------------------------------------------------------------


The hosts file is loaded into memory at startup. It would first check the hosts file entries before querying the DNS servers.

Now if there is a DNS server with the hostname in the hosts file, the host file entry would override it. So you can as well have a host file entry with the name www.google.com and point it to your custom search app ;)

This of course has ample implications.

  1. For development environments, this could be ideal, where you are restricting the access to a set of users and accessing the site with a custom hostname as specified in the hosts file.
  2. Taken from http://winhelp2002.mvps.org/hosts.htm
  3. You could use it as a tool to block unwanted sites. Eg. Ad sites which slow down the loading of a webpage. A list of such sites can be added into the hosts file. So you don't always need an anti virus to do all the job. A simple entry in the hosts file to a non-existent IP can save you from unwanted sites. There are fully designed hosts files containing entries to block most of the malicious sites. You could google around if you are interested.
There's one thing you can't rule out. If a malicious software, gets hold of the hosts file, it could make changes to your hosts file and point you to a dup site containing malicious content and you would actually not come to know of it.

No comments:

Post a Comment