Can't block websites using Terminal

Hey everyone, having some trouble with the below and wanted to see if anyone has solutions or ideas! Asked around, even in Reddit, without any luck so far:


PROBLEM:

Can’t block websites for productivity via hosts in Terminal on personal computer. Don't want to use Screen Time because it's easy to workaround.


It worked successfully on my work computer, so know it's possible. However, no luck on my personal computer. They’re the same Mac models and I’m using the same WiFi router for both.


MAC DETAILS:

MacBook Pro, 2023 with Ventura 13.4.


SO FAR:

I’ve followed all of the below instruction and, again, it worked on my work computer, but not personal one:


  1. Type in the command below and press Return on your keyboard. This will open the hosts file: sudo nano -e /etc/hosts
  2. Use the arrow keys to go to the bottom of the line. Type 127.0.0.1 and the website address you want to block. For example, to block YouTube, I would enter the following in Terminal: 127.0.0.1 www.instagram.com
  3. Type each website on a separate line. Once you’re done, press Control + O followed by Return on your keyboard to save the file, and then Control + X to close the file.
  4. Type the following command to flush the cache, which will enforce these changes across the browsers. Press Return to enter the command: sudo dscacheutil -flushcach (I've also tried: sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder)


Full instructions found here.


TROUBLESHOOTING ATTEMPTS:

  • Tried different variations of the URLs:
  • with/without www.
    • with/without https://
  • Tried using 0.0.0.0
  • Tried using with and without a tab after the numbers
  • Cleared caches (Safari & deleted caches out of Finder folder), restarted, etc.

While these forum posts are older, I tried them without luck:


Forum 1

Forum 2


Here's what I'm seeing on my end for a quick example:




Any help will be much appreciated and hope it helps others in the same boat... thank you!

MacBook Pro 14″, macOS 13.4

Posted on Jun 20, 2023 2:27 PM

Reply
Question marked as Top-ranking reply

Posted on Jun 21, 2023 3:10 PM

yokevinnn wrote:

Thanks for the response! For your note on the last entry, do you mean the line with https? (Wonder if an incorrectly formatted entry has any effect on it functioning?)


This file is for domains only, is decades older than URLs and HTTPS and related, and is older than DNS itself.


Best case, the error here gets ignored.


Worst case, the error causes something (else) to tip over.


This text file is a very ancient and low-level and central part of IP networking.


The directions you're following are amusing, too. This part of the directions isn't going to work at all well: "For example, to block YouTube, I would enter the following in Terminal: 127.0.0.1 www.instagram.com".


And the cache flush command shown s also incorrect. It's more properly this:

sudo dscacheutil -flushcache


If you try to use the command listed, you'll get an error:


% sudo dscacheutil -flushcach
Password:
Usage: dscacheutil -h
       dscacheutil -q category [-a key value]
       dscacheutil -cachedump [-buckets] [-entries [category]]
       dscacheutil -configuration
       dscacheutil -flushcache
       dscacheutil -statistics
% 


I didn't look for other errors or issues with the directions.


I'd use Screen Time here, or would use Pi-hole or something else here, or a DNS-blocking service, and would generally discourage using the /etc/hosts file for this and such. It'll work for what you're trying yes, if you're careful, and if the directions are correct. Or that Rescue Time app mentioned earlier, if that works for you. For some folks, I've also removed the problem apps. Forcing a new download slows down the habit.

Similar questions

19 replies

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Can't block websites using Terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.