We welcome you to our series “Working with Hosts File” where you will get the basic understanding of the hosts file, you will understand the role of the hosts file plus you learn how to locate and open the hosts file. Then, you learn how to edit the hosts file and play with it. In addition, you learn how to hack the hosts file. Finally, you learn how to work with the custom hosts file.
[Recommended Reading – Hack The Hosts File – Part 2]
[Recommended Reading – Custom Made Hosts File – Part 3]
This is the first post in the series, in which we will discuss the following topics about the hosts file:
- Understanding the Linux & Windows Hosts File
- Role of the Hosts File
- Locating the Hosts File
Understanding the Linux & Windows Hosts File
The hosts file, which lies in your operating system associates or maps host names with IP addresses.
You may get baffled by this technical definition of the term. So, in simple words, you can say the hosts file is nothing but the hosts file is sort of an address book. This file contains various addresses (host names) for example, www.XYZ.com and their respective calling numbers (IP addresses) for example, 127.0.0.1.
Let us now understand the basic role of the hosts file.
What is the Role of the Hosts File?
Let us just break down the whole process for you in simple terms.
Whenever you enter a host name or as you normally say a website’s address for example www.techtricksworld.com in your web browser’s address bar, your browser gets connected to the DNS (domain name server) of your ISP (Internet service provider) to get the IP address associated with the website. The server tells the IP address in return and the website opens in your browser. This whole process just completes in a few seconds and now a question might pop up asking but, where was the hosts file? What did the hosts file do basically?
The answer is that when you enter a hosts name in your browser’s address bar, the browser automatically first searches for the calling number (IP address) of that site in the hosts file. If it finds the correct entry, the website opens in the browser. If it does not, the browser connects to your ISP for getting the IP address of that site. So every time, you try to open a website in your computer, the hosts file in your operating system is consulted to get the IP address of the site.
However, most of the times, the hosts file does not contain IP addresses and the host names, so the browser skips past through it fast to connect to the ISP for getting IP address. This is simply because we have never put any host names and IP addresses in the hosts file, maybe because we simply do not know how to.
So, let us now learn about locating the hosts file.
Locating the Windows Hosts File and Linux Hosts File
Locating the hosts file differs for different operating systems. However, we have considered the two most used operating systems- Windows and Linux.
For Windows users:C/Windows/System32/drivers/etc/hosts (the path).
For Linux users:/etc/hosts(the path to locate the hosts file).
NOTE: In our case, we have illustrated the steps in Windows
Perform the following steps to locate the hosts file:
- Browse to the location of the hosts file entering the path C:\Windows\System32\Drivers\etc in the address bar of File Explorer(Fig.Hosts-1).
- Double-click the hosts file to open it, as shown in Fig.Hosts File-1:
NOTE: The hosts file is the one without any extension; you can open it in notepad.
The hosts file is opened, as shown in Fig.Hosts File-2:
So, this ends our first post of the series. We hope you got the basics intact and understood them well. Stay connected to find out more about the hosts file in our second posts of the series.