Understanding Hosts File and How to Use it

what is the hosts file
Image by rawpixel.com on Freepik [Edited]

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.

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! 😀

hosts file

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:

hacked

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! 🙂

21 Comments

  1. Amit Shaw
    • Zainil
  2. Mosam Gor
    • Zainil
  3. Evan
    • Zainil
  4. Atish Ranjan
    • Zainil
      • Peter Lee
        • Zainil
  5. Ray
    • Zainil
      • Ray
        • Peter Lee
        • Zainil
  6. abhishek
    • Zainil
  7. Praveen Bhardwaj
    • Zainil
  8. Kshitij Jain
  9. sachin