Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

colonel179

macrumors regular
Original poster
Jun 10, 2014
111
79
Hello,

Some years ago I used to block websites using the command sudo pico /etc/hosts on terminal. However, I tried it again today and it doesn't work. I am currently on Big Sur on a 2015 MacBook Pro 13"

When I type the websites, it just ignores completely the command and it doesn't work. I searched in google and found that it might be due to having the connection with IPV4 instead of IPV6 or something like that, and it said something about putting a different line of text but it didn't work either.

Does anyone know how I could make it work? Is there a new command or something else that could work like this used to?

I would really appreciate it!

Thanks you all!
 

martynhare

macrumors newbie
Apr 20, 2021
7
3
Are you running this afterwards to ensure it’s loaded in?

sudo killall -HUP mDNSResponder

I believe Avahi/Bonjour is used to cache the hosts file meaning changes don’t take immediate effect until the above is ran. Also, make sure you’re not using a third party browser with DoH support enforced, as that can cause hosts files to be ignored under some circumstances, depending upon how it is coded.

On a side note: If you just want to block websites inside your browser, have you considered using Screen Time within System Preferences to do it? Alternatively, if the reasoning is to block advertising, then AdGuard combined with Little Snitch makes for an even nicer solution than just DNS blocks alone.

I personally run with root enabled and marked IsHidden with sudoers configured as ‘Defaults rootpw’ and with my (only) user account removed from admin group but manually added to sudoers instead. This lets me have the best of both worlds with Screen Time enforcement while satisfying my power user needs with brew. To stop a future update owning me (because one never knows what Apple does and doesn’t test for when blitzing files) sudoers is uchg+schg (immutable) flagged on my system.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.