Hacking the hosts file in windows

neo_vi's Avatar author of Hacking the hosts file in windows
This is an article on Hacking the hosts file in windows 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 to tell the browser to take the files from the local web server 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:
# rhino.acme.com # source server
# x.acme.com # x client host localhost
Change the last line to whatever name u like.
Code: 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.
Code: dont-see-this.com

How the above line works?

If you go to 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 which is your localhost.
(The above technique is used in 'spybot search and destroy' when u give the immunize option)
Happy hacking!
ramakrishnanjk like this
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Same process is used by many virus to block the anti virus sites and that means you cannot update your anti-virus thus preventing the removal of virus
pankaj.sea's Avatar, Join Date: Apr 2009
Pro contributor
Hi neo_vi
There was a small mistake in your article, the path of "hosts" file will be
venami's Avatar, Join Date: Dec 2008
Ambitious contributor
Nice info neo_vi.

And in Linux, the same can be done in /etc/hosts file.
neo_vi's Avatar, Join Date: Feb 2008
Invasive contributor
Originally Posted by pankaj.sea View Post
Hi neo_vi
There was a small mistake in your article, the path of "hosts" file will be not
Oh. I am sorry. Thanks for letting me know. It happened cos i didn't copy the path, i typed it instead.

>>> for shabbir,
can u please make the above change in the article.?
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
technica's Avatar, Join Date: Dec 2007
Good one. I have already used it some times, but with this article I understood how it works.
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Nominate this article for Article of the month - Dec 2009