What Is The Hosts File?
A hosts file stores information about a specific computer system on the network. It essentially maps the host’s name!
Each and every time when you start typing the domain name, the browser would, without human intervention, be connected to the server of Domain name system of the Internet service provider and the DNS will inform your Browser the Domain Name and the IP Address. ❓ ❓
I think these jargons have bounced over the brain; so let me explain you with a small example! 🙂 Suppose you want to surf over “Computerhowtoguide.com”, so what you will do is, open your browser and type http://computerhowtoguide.com in your browsers address bar. Once you press enter, your browser will pass a message to your ISP’s DNS (Domain Name Server). This server will in return tell you the IP address of “Computerhowtoguide.com”.
You might be thinking that this is a very big process, but all these would happen in just an eye blink! 😯 Yes, it is that fast. But now you must be wondering, where is the hosts file in the picture!?!?! So now let me bring the hero into the role! 😎 So here comes the role of the hosts file!
Use of The Hosts File
As you have seen that, every time you want to visit a website, your browser connects with the DNS of your ISP! But what if you don’t want to connect to your ISP every time? Here you can use the hosts file. Now I will once again quote the definition of the hosts file:
Hosts files are the files which store information about a specific computer system on the network. It essentially maps the host’s name.
Now I am sure that you are thinking on the right track! 🙂 In your hosts file, you need to enter the domain name and its IP address. Thus now when you will enter the domain name in your browser and press enter, your browser will 1st search the domain name in the hosts file and once it finds the relevant entry, it will directly map your browser to that particular hosts name.
All the concept of the hosts file must now be clear to you, but now you must be wondering where to find the hosts file? How to edit it? What, when, where etc.. etc… Let’s go 1 by 1!
[More from us: Choosing The Right Web Browser for Your PC]
Location of The Hosts File
Every operating system has a hosts file, but the location of the hosts file is different in each OS. In this post, I am considering the directories of the 2 most used operating systems i.e. Windows and Linux.
For Windows OS users, the following is the path:
C/Windows/System32/drivers/etc/hosts (C is assumed to be your system drive)
The following is the path for Linux OS users:
/etc/hosts
One noteworthy thing: the hosts file doesn’t have any extension. You just have to double click on it to open it. Windows OS users can open it with Notepad.
Once now you have found the hosts file, your curiosity would rise towards, how to use the hosts file? How to get the IP address of the desired domain name? Let’s slow down step by step:
How to Find The IP Address of Any Domain Name – Ping Command?
Before doing this experiment, one very important thing is, you should be connected to Internet while performing; if you are not connected to the Internet, you won’t be able to find the IP address of the desired domain.
[More from us: Share Internet Access via The Open Garden App]
Ping Command
By using the Ping command you can find the IP address of any domain name you want. Here I am exploring the ping command on Windows OS. Ping command is to be used on the command prompt. So 1st open the command prompt Press Ctrl + R. Now in Run, type cmd and press OK. Next, the command prompt will open. Now in the command prompt, you need to use the ping command.
In the command prompt, the 1st command that you will find is C:\Users\User Name>
Now you have to type “ping domain name” and press enter.
Eg: C:\Users\User Name>ping www.computerhowtoguide.com
Now you will find the IP address of Computerhowtoguide in the command prompt; you will find the IP “184.173.228.93”.
Thus now you can conclude that the IP address of Computerhowtoguide is 184.173.228.93!
Now that you have found the IP address of the desired domain name, now comes the time to edit the hosts file, so now let’s move on the next question, how to edit the hosts file ! 😎
How to Edit The Hosts file?
Editing the hosts file is really very simple. To edit the hosts file, 1st open the hosts file and just name a new entry at the end. Type the IP address of that domain name followed by the domain name:
Eg: 184.173.228.93 www.computerhowtoguide.com
Done! 🙂 Now it’s time to play with the hosts file! 😎 Would you like to play a prank on someone? If yes, then lets go for it! 😀
Now that you know all about the the hosts files, its time to have fun with it! 😀 😎 So now lets make some hacks out of the hosts file:
Hack The Hosts File
As you know that, when you type the domain name in the address bar of your browser and then click on enter, then browser will 1st check for the IP address of that domain name in the hosts file; if it doesn’t find that particular domain name’s entry in the hosts file, then it will contact the DNS of your ISP to find the IP address of the entered domain name.
So now what you can do is, you can make a fake entry, I mean, you need to make an entry in the hosts file, but the IP address that you will enter, should not correspond to the domain name of that entry! 😉 I hope you have got the prank, else let me explain you with an example:
Suppose the IP address of www.xyz.com is 123.45.79.89. Then the entry that you need to pass in the hosts file is: 123.45.67.89 www.computerhowtoguide.com
Thus now every time when someone will try to open www.computerhowtoguide.com from your system, automatically www.xyz.com will be loaded! 😯 I am sure that you know what’s www.xyz.com! 😛 😉
I hope you have enjoyed reading this long post on the hosts file and you will enjoy playing with it too. But please make a point that you don’t harm anyone with the hacks mentioned in this post. These hacks are mentioned only for educational purpose and not for harming someone. Thank you for your cooperation! 🙂
Hey Superb +1 Post Zainil 😉
Would love to give it a try 😀
Thanks mate.
Hey Amit bha! 🙂
Thank you for your kind words! 🙂 And I am sure you will enjoy playing the hosts in your system, opps rather playing with the hosts in other people’s system! 😀
Hi Zainil Dedhia,
Great Post!
First, thanks for sharing.. very well explained in detail..
Mosam
Hi Mosam,
Thanks a million for the appreciations! 🙂
Actually I had some experience with this thing but not so detailed like you described here. Anyway, now i know how do deal with Host files. Well, it is more like black magic to me, thanks for some clearness.
Black Magic! 😀 So now you have got the supernatural powers to perform the black magic ! 😎
Enjoy playing with the hosts files! 🙂
Great post Zainil. A lot to learn from this post. playing with host files is veryenjoyable. keep writing such great piece of writing.
🙂 Thanks Atish! 🙂
Between it feels soo kewl when 2 partners of a blog are discussing through comments on some other blog! 😀 😎
I hope Peter doesn’t mind this! 😉 😀 😀
Not at all, Zainil 🙂
😉 🙂 😀
I have been using a custom host file for a long time. At least 10 years, and maybe a little longer. I primarily use it for blocking ads and malicious sites. I know some security software will automatically write to your host file too. I have a lot in my file, which slows my browser down slightly. Not too much but a little. I figure I can live with a half second or less slower page load though. I guess it would be a little funny to mess with someones host file and redirect their favorite site to somewhere else.
Hi Ray! 🙂
Custom hosts file? What did you exactly do? And how do you block malicious sites with it, I mean do you have some specific code which blocks all the malicious sites automatically? Please share your knowledge! 🙂
A nice site that provides a custom windows host file is:
http://winhelp2002.mvps.org/hosts.htm
On that site you can download their pre-made host file. Rename your original host-backup (just in case) and drop in the host file that they provide. After doing so you need to close out all browsers and tabs whether it be Google Chrome, IE, Firefox, etc. Then, start your browser back up for the changes to take effect.
They do update it often so you need to visit the site for updates and get the latest host file several times per year. At this time the last update was January 18th, 2013.
It is definitely worth reading the page entirely.
I use the “Manual Install Method”. Unzip the download and copy the provided host file to the appropriate location.
It does have entries to block ad networks, but also parasites, hijackers, and unwanted spyware programs.
So it will block things like adsense too, which I am sure some people would rather not want their visitors to be doing, but there are plenty of other software and browser based addons and extensions that do something similar. You can simply remove the lines for these or comment the line out if you wish.
Like I mentioned some security and anti-spyware programs will write rules/entries to your host file. I couldn’t tell you which ones do right off hand, but I have used some in the past that do.
If you use it and you find that you can’t access a specific site it is likely because this host file is preventing it. You either need to remove the line or comment it out.
There are a lot of sites in the host file that it will block. Open it up with notepad and review the entries. A lot of them are ad networks, but there are quite a few not so nice ones in there too.
It takes a little tinkering to get the hang of, and a little getting used to.
You can open the host file with notepad and add your own custom rules. If you wanted to block a specific site, image, network, or what have you just add to the file like 127.0.0.1 sitename.com. To block a specific ad or network just right click and find the source. Then, just add 127.0.0.1 network-name.com. It is sort of the equivalent of deny from.
Another thing that it will do is block video ads. If you start up a video and see a blank screen for 30 seconds and wonder why the video is not doing anything it is because it is blocking the ad.
Some people like it and some don’t. I like it and have been using it for a long time. It also helps prevent some data collection on your browsing habits that some sites love to collect.
If used properly it adds a little more protection. Whether there are other security sites that provide a similar host file I couldn’t tell you.
For me it’s a combination of this sites host file and adding my own custom rules to it.
Anyway check the link I mentioned. It may or may not be right for you.
Thanks for sharing, Ray! I always get to learn something new from you! 🙂
Man this is truly awesome ! Really got something amazing Ray.. I am surely going to use this host file!
Thanx a million for sharing this Ray! 🙂
Nice tutorial , it covers everything about host files
Hi Abhishek! 🙂
I am glad that you enjoyed reading the post! 🙂 Thank you for stopping & commenting here! 🙂
Deeply explained as always. Thumbs up. Keep up the good job.
Thanx Praveen for your kind words! 🙂
Really Nice tutorial on how to edit hosts file, I know about how to edit these files, but what to do after editing these files is now clear. Thanks once again.
nice info
now i understand what exactly is host file