host file to block websites in Windows, Mac and Linux
There is a file named “hosts”, which contains the mappings of IP addresses to host names.
For example, if you put the following line in the “hosts” file, it will maps the host name www.google.com to the ip address 127.0.0.1. As a result, when you type www.google.com in the browser, it will bring you to the ip address 127.0.0.1 instead of the google website.
127.0.0.1 www.google.com
To block or restrict certain websites, you can just put a dummy ip address followed by the website address you want to block in the file “hosts”. You will need to edit this file as an admin.
The location of the hosts file in Windows:
C:\Windows\System32\drivers\etc\hosts
The location of the hosts file in Mac OS or Linux:
/etc/hosts
To edit the hosts file as an admin in Windows, right click the text editor you use and select “Run as Administrator“, open the hosts file from the text editor menu.
To edit the hosts file as an admin in Mac OS, go to Applications->Utilities, open Terminal and type the following, enter the password when asked.
sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit /etc/hosts
Search within Codexpedia
Search the entire web