How to Block a Website in Safari

Open the Terminal., Open the hosts file., Scroll to the bottom of the file., Type in the sites you want to block., Save and exit the editor., Flush your DNS.

6 Steps 1 min read Medium

Step-by-Step Guide

  1. Step 1: Open the Terminal.

    To block specific websites, you will need to edit your "hosts" file.

    This file determines what can and cannot be accessed by the computer's network adapter.

    Adding websites to this file will prevent them from loading in any browser, including Safari.
  2. Step 2: Open the hosts file.

    Type sudo pico /etc/hosts and press Enter.

    You will be asked to enter in the Administrator password.

    The hosts file will open in the Terminal's text editing program. , Use your arrow keys to navigate.

    Create a new line by pressing Enter. , For every site you want to block, enter
    127.0.0.1 example.com and press Enter.

    Each entry should be on its own line. , Once you have entered all of the sites that you want to block, save and exit by pressing Ctrl + O and then press Enter. , In order for the settings to take effect, you will need to flush your cash.

    You can do this by typing sudo dscacheutil
    -flushcache and pressing Enter.

    For more details on flushing the DNS, see this article.
  3. Step 3: Scroll to the bottom of the file.

  4. Step 4: Type in the sites you want to block.

  5. Step 5: Save and exit the editor.

  6. Step 6: Flush your DNS.

Detailed Guide

To block specific websites, you will need to edit your "hosts" file.

This file determines what can and cannot be accessed by the computer's network adapter.

Adding websites to this file will prevent them from loading in any browser, including Safari.

Type sudo pico /etc/hosts and press Enter.

You will be asked to enter in the Administrator password.

The hosts file will open in the Terminal's text editing program. , Use your arrow keys to navigate.

Create a new line by pressing Enter. , For every site you want to block, enter
127.0.0.1 example.com and press Enter.

Each entry should be on its own line. , Once you have entered all of the sites that you want to block, save and exit by pressing Ctrl + O and then press Enter. , In order for the settings to take effect, you will need to flush your cash.

You can do this by typing sudo dscacheutil
-flushcache and pressing Enter.

For more details on flushing the DNS, see this article.

About the Author

D

Deborah Simmons

Enthusiastic about teaching home improvement techniques through clear, step-by-step guides.

64 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: