The hosts file in Windows is used to map the IP address to a domain. It can be used to block access to domains, by mapping the host name to an incorrect ip address or a local ip address. If a host is mapped in the host file, Windows will not query the DNS server for the resolution.
The default location for the hosts file is C:\Windows\System32\drivers\etc, the file has no format and needs to be opened using notepad or another text editor.
The user will need administrator permissions to edit the host files in windows – So Let’s get started!
Firstly, open notepad as administrator:
For Windows 7/Vista:
Click Start and type notepad in the search bar, right click on the notepad file and select run as administrator
For Windows 8/8.1/10:
In the tiles mode, type notepad and right click on it and then choose rus as administrator
Once you have the notepad open, Click File -> Open and get into the folder C:\Windows\System32\drivers\etc you may not see any files listed in there, so be sure to select All Files and then double click the hosts file to open it.
Now double click the hosts file and open it. This will open the Hosts file in notepad as administrator. Entries, in the hosts file are in the following format:
if a line has a # before, eg: #127.0.0.1 localhost, then it is commented out and will not function. To add an entry to host files, add the line just below this line, without the #. The correct format is
IP ADDRESS HOSTNAME
Once this is entered, Click File -> Save to save the hosts file, or press CTRL + S keys. If you wish to edit it later, simply re-open the file, make the modification and save it again.
There are various uses for the hosts file, ex: i used to use it to test local website, on a domain without actually having to buy the domain.