
If we map that to Facebook in our hosts file, any time someone using the Mac tries to go to Facebook, they’ll see The New York Times load instead. For example, The New York Times website returns an IP address of 170.149.172.130.


In our case, we want to block Facebook so we’ll map to 0.0.0.0 which, as an invalid IP address, which will result in an error.Īlternatively, you can enter the IP address of a valid site instead of 0.0.0.0, which will result in users attempting to access Facebook being directed to the site of your choosing.To do this, type the IP address you wish to assign, followed by two tabs and the hostname.In our example, we’ll pretend that the computer we’re using is a device that we want to use exclusively for work, not allowing ourselves to get distracted by Facebook on our work machine. In addition to testing newly developed websites and web hosting migrations, another reason to edit the hosts file is to block access to specific websites. To edit the file, you’ll add your own lines after broadcasthost.

It also contains default IP values for localhost and broadcasthost. For each line, any text after the pound sign is ignored by the computer, making it a good way to add notes and descriptions to your files. Any line that starts with a # sign is a comment and is not read by the /etc/hosts file.
