Before explaining the Host file let me first briefly explain you the backend process which occurs when you open a web site from your browser. At first when you type in your browser the address of the website you wish to connect, it will send a message to the DNS server of your Internet service provider (ISP) which will in turn send the domain name and IP address of the website to your browser. But all these processes take place only after the browser checks within the Host file.
Now coming back to the host file, it is a file which contains IP address and Domain name of the sites separated by a space between them. When a domain name is typed in the browser it will first check in the host file for that domain name. If it finds a match it will directly use its corresponding IP address and if a match is not found then it will take the traditional method of requesting the IP address from the DNS server of your ISP.
Different operating systems have different locations of the host file:-
For Windows OS users, the following is the path: C/Windows/System32/drivers/etc/hosts (C is assumed to be your system drive)
For Linux OS users the following is the path: /etc/hosts
Host file does not have any extensions and for windows operating system they can be opened in Notepad.
In order to use the Host file, you will require IP address which can be derived from the command prompt using the ping command. Open the command prompt by typing CMD in run. Once command prompt is opened type ping domain name (Example: ping www.google.com) you will get the IP address of the domain name www.google.com. But before editing the Host file take a copy of the original file as back up so if anything goes wrong you can correct it with the help of the backup.
You can now add the IP Address and domain name in the host file by adding a new entry. Example: 192.168.1.1 www.google.com and then save the file. Make sure that the IP address and the domain name are separated at least by one space and also at least one blank line is present at the end of the Host file. Now whenever you type www.google.com in your browser instead of connecting to the DNS server of the ISP it will directly fetch the IP address from the Host file from where it will get the IP address as 192.168.1.1
Note: You can edit the Host file only as an administrator. You can list multiple domain names for one IP address on a single line.
Host file has number advantages:
- Host file helps in increasing the browsing speed due to reduced communication between the browser and the ISP.
- It helps in blocking unwanted advertisements by typing the IP address of any other website in front of the domain names of such advertisement sites.
Thus, when a Host file is used correctly it will save your time and give a much secured environment.