Wednesday, December 2, 2009

Hacking the hosts file in windows

Many of us would have used a local webserver for designing websites or for previewing. This is where the 'localhost' comes. We always give http://localhost or http://127.0.0.1 to tell the browser to take the files from the local webserver instead of going into the internet. How and where to change that name, if u wanted to make the localhost as .com or .net, whatever.
Just edit the file named hosts under the location
'C:\WINDOWS\system32\drivers\etc\hosts' (assuming C: is the drive where u installed windows)
A default hosts file will look like this

# Copyright (c) 1993-1999 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

127.0.0.1 localhost

change the last line to whatever name u like.
e.g

127.0.0.1 xyz.com

Use the name xyz.com instead of localhost while using the local webserver.

This file can also be used to block unwanted sites. U can put the sites here that u don't wish to see.
e.g

127.0.0.1 dont-see-this.com

How the above line works?
If you goto a particular url in the browser the OS will check the hosts file whether any specific address has been mapped to that site.If yes it will load that,if not it will fetch it from the web. If you give the above line in the hosts file, whenever u goto the site 'dont-see-this.com' it will point the browser to the address 127.0.0.1 which is your localhost.
(The above technique is used in 'spybot search and destroy' when u give the immunize option)
Happy hacking

1 comment:

  1. Hey.. its very usefull... Keep posting such tips on hacking...

    Vikram

    ReplyDelete

Page Counter