Home News Update How-To Guides Detail article

How to Block Facebook Using the Hosts File on Windows and macOS and Linux

By following these simple steps, you can effectively block Facebook on your computer, helping you stay focused and avoid unnecessary distractions.
How to Block Facebook Using the Hosts File on Windows and macOS and Linux

For Windows:

1, Open Notepad as Administrator:
  • Press Win + S and type "Notepad."
  • Right-click on Notepad and choose "Run as administrator."
2, Open the Hosts File:
  • In Notepad, go to File > Open.
  • Navigate to C:\Windows\System32\drivers\etc.
  • Change the file type from "Text Documents" to "All Files" in the bottom right corner.
  • Select the hosts file and click "Open."
3, Edit the Hosts File:
  • At the bottom of the file, add the following lines:
127.0.0.1   facebook.com
127.0.0.1   www.facebook.com
  • This redirects Facebook's URLs to your local machine, effectively blocking access.
4, Save the File:
  • Save the changes (Ctrl + S) and close Notepad.
5, Flush DNS (Optional):
  • To ensure the changes take effect immediately, you can flush the DNS cache.
  • Open Command Prompt as Administrator (Win + X > "Command Prompt (Admin)").
  • Type ipconfig /flushdns and press Enter.

For macOS and Linux:

1, Open Terminal:
  • On macOS, you can find Terminal in Applications > Utilities.
  • On Linux, Terminal is typically found in the system's main menu.
2,Edit the Hosts File:
  • Type the following command to open the hosts file in a text editor:
sudo nano /etc/hosts
  • Enter your password when prompted.
3, Add the Blocking Lines:

  • At the bottom of the file, add the following lines:
127.0.0.1   facebook.com
127.0.0.1   www.facebook.com

4, Save and Exit:
  • Save the changes by pressing Ctrl + O, then press Enter.
  • Exit the editor by pressing Ctrl + X.
5, Flush DNS (Optional):
  • On macOS, use:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
  • On Linux, you might need to restart the DNS service or use:
sudo systemctl restart network-manager


Testing:

Open your web browser and try to visit facebook.com. It should be blocked.
These steps should effectively block Facebook on your computer.