How to Block/Unblock Websites on a Mac Using Terminal

Nowadays, there always will be some distractions that drag you from working. It can be regularly checking your emails, reading your Instagram, Facebook, Snapchat feed, or watching YouTube videos, etc. Blocking these websites can keep you productive during work, and here are some methods that can help you block or unblock websites on Mac.

Focus on Setapp: Filter out distractions and stay on task
Focus on Setapp: Filter out distractions and stay on task

How to Block/Unblock Websites on a Mac

Using The Terminal app

Step 1: Open the Terminal.

block/unblock websites on Mac

Step 2: Type the command line below and hit Enter:

sudo nano /etc/hosts

block/unblock websites on Mac

Then, you certainly will be asked about administrator password of your Mac.

Step 3: Once you type enter the password successfully, the hosts file will be opened by Terminal.

Step 4: Create new line by pressing up or down arrow button and then type the IP “” + “Space” + “URL or Website address.” And type another URL or Website address following the same steps.

For example:

block/unblock websites on Mac

Step 5: When you have done the list of sites or URLs, you can save the hosts file by pressing the Ctrl + O and then hit Return button. Finally, press the Ctrl + X to exit the screen.

block websites on mac

Step 6: Flush the existing cache by using the command line blow, this will refresh the existing cache on the host database.

sudo dscacheutil -flushcache

block/unblock websites on Mac

Now, go to the URLs or Sites that you have blocked. If you have already edited the hosts file correctly, you should not be able to access that URL and Site address.

block/unblock websites on Mac

To unblock, just delete the sites or URLs which you have added to the hosts file and don’t forget to flush the DNS cache as well.

Using The Built-in Parental Controls

You can easily use the built-in Parental Controls on MacOS to block user accounts directly from accessing to some websites. This will explains how you can block websites by using Parental Controls in detail.

Step 1: Create an individual User Account for your children.

Step 2: Browse to your Apple menu and click on “System Preferences.”

how to block websites on mac 1

Step 3: Select Parental Controls icon.

how to block websites on mac 2

Step 4: Then select the Lock icon ( displayed at the end of the window).

how to block websites on mac 4

Step 5: Select the Lock icon, you will certainly be asked to type in the password of Mac. Click on to Unlock.

Select Create a new user account with parental controls >> Click Continue.

how to block websites on mac 3

Then fill out the user’s age, full name, account name, make a password and a password hint (if needed), and then click on “Create User.”

how to block websites on mac 5

Step 6: Then select the User account which you need to lock. MacOS provides you controls under five categories including Apps, The Web, People, Time Limits, and Other controls.

Step: 7: Choose Web tab and select Try to limit adult websites automatically and click on Customize… button.

how to block websites on mac 6

Step 8: Under Never allow these websites, select “+” button and type the URLs and Websites which you need to block.

how to block websites on mac 7

Now, if a kid user access to sites which you have prevented, they’ll come across a notification such as this.

how to block websites on mac 8

Using The Third-party app – SelfControl

SelfControl is a totally free and open-source app for MacOS which allows you block your own access to sidetracking sites, your webmail, or something else on the web. It enables you to block a specific website or websites for a particular amount of time.

When you need to focus on a project for three or four hours without being able to use Facebook, Twitter, you can easily set the timer for three or four hours to block the sites. It will only be unblocked when the time limit expires. If this seems like it’ll be great to you, keep reading!

Step 1: Download and open the SelfControl app from here.


Step 2: Click on Edit Blacklist button.

block website using SelfControl

Welcome to SelfControl

block website using SelfControl 1

Step 3: Click on the (+) button to add the site which you want to block it on Mac.

block website using SelfControl 2

Step 4: Your blacklist window may look like the image above. Then, close the blacklist window now, and drag the slider in the main window to set the time you want the sites to be blocked for a min of 15 minutes and a max of 24 hours.

Step 5: Finally, click on Start button.

Read also: How to block websites on iPhone and Android

5/5 - (1 vote)



Solomen is the founder of and is at his happiest when he's working with technology and is able to help others. In his free time, he often listens to Baroque music and goes swimming. Feel free to contact him on social media!

Notify of

Oldest Most Voted
Inline Feedbacks
View all comments

I also used the first method and would like to know how to undo the commands

Swati Anshu

Hey! I did try the first way and it worked! Although now I need to unblock it and I am unable to do so…I would appreciate a step-by-step process on how to unblock the sites. Thank you!

MrHow - Tutorials Related To Windows, Mac, iOS & Android