Sometimes you will need to edit the host file on your computer. Through file hosts, you can control access to websites and network traffic.
The host file has been in use since ARPANET. They are used to resolve host names before DNS.
Microsoft keeps the hosts file in the Windows network, which is why it changes so little even if it is used in Windows, macOS or Linux.
The first part will be the location to redirect the address, the second part will be the address you want to redirect and the third part will be the comment. They can be separated by a space, but for readability are usually separated by one or two tabs.
Windows 8 or 8.1 and 10
If you use Windows 10, the way to edit the host file will look like this:
When you're done, open the following file using the File -> Open feature: c: windowssystem32driversetchosts
You can then edit as usual.
Windows 7
To access the hosts file in Windows 7, you can use the following command in Run to open notepad and file.
When notepad is open, you can edit the file. In this example, we will block Facebook. To do this, simply enter the following after the www.facebook # com
After editing the host file, save it.
Now if you try to access Facebook in IE it won't work. We also cannot access Facebook through Google Chrome.
macOS (Any Version)
In macOS, accessing the host file is also quite easy. Start in the terminal and use the editor.
The files will look a bit like Windows, though not as intuitive. Again we will block Facebook.
This time use 0.0.0.0 as a loopback and will direct you to the computer's Apache test page.