Your Mac’s hosts file is a small, but important text document that has the ability to map hostnames to specified IP addresses. Although the modern internet uses a variety of public and private DNS servers to map IP addresses, the hosts file is a handy way to override those DNS servers, allowing you to manually point a website address to a any IP address.
Edit Your Mac Hosts File with Textedit application:
You need to copy the file to an unprotected location, like the desktop, edit it, and then copy it back.
To find the hosts file, open Finder and, in Finder’s menu bar, select Go > Go to Folder. In the box, type the following location and press Return.
To edit the file, you’ll add your own lines after broadcasthost.
If you want to block Facebook you can add http://www.facebook.com 0.0.0.0 which, as an invalid IP address, will result in an error.
Then, drag and drop the hosts file from your desktop back to its original location at /private/etc and replace.
If you need to flush your DNS cache because the site isn’t loading.