The “HOSTS” file is a computer file used by an operating system to map hostnames to IP addresses. The file is used for several purposes, including:
Block websites: You can use the HOSTS file to block access to specific websites by mapping the hostname of the website to an invalid IP address.
Redirect websites: You can use the HOSTS file to redirect traffic from one website to another by mapping the hostname of the original website to the IP address of the new website.
Speed up domain name resolution: By mapping frequently visited websites to their IP addresses in the HOSTS file, you can improve the speed at which your computer resolves the domain names of those websites.
The HOSTS file is a simple text file, and can be edited using a text editor such as Notepad on Windows or TextEdit on macOS. The file typically resides in the following locations:
- Windows:
C:\Windows\System32\drivers\etc\
- macOS:
/private/etc/
- Linux:
/etc/
To edit the HOSTS file, you will need to have administrator privileges.
Here’s an example of how you can use the HOSTS file to block access to a specific website:
Open the HOSTS file using a text editor.
Add the following line to the file:
127.0.0.1 example.com
- Save the file.
This maps the hostname “example.com” to the IP address “127.0.0.1”, which is the localhost address. Any attempt to access “example.com” will now be redirected to the localhost, effectively blocking access to the website.
Note: Keep in mind that the HOSTS file is a simple text file and is not a very secure way to block access to websites. Advanced users may be able to bypass the blocks by editing the HOSTS file themselves.