1

When I try to block websites on terminal (etc hosts..) it works. But when I try to do it with Youtube, it doesn't.

Typing youtube.com as a url won't open it, but if I search youtube on google for example and then click on it, it will work (redirections.)

I tried to type all forms of "youtube.com" , with https/www, without, I cleared cache, restarted my mac. Nothing worked.

Is there a way i can fully block Youtube?

Thanks

5
  • 1
    Exactly what do you have in your /etc/hosts file to block it? Note that adding an entry for youtube.com does not block www.youtube.com or any other (sub)domain. Also, adding an IPv4 entry (e.g. "0.0.0.0 www.youtube.com") does not block IPv6; you need another entry for that (e.g. ":: www.youtube.com"). Commented Oct 21, 2019 at 19:56
  • I put [127.0.0.1 www.youtube.com] So what should i put? I didn't understand the " : : www.youtube.com"
    – kamran1124
    Commented Oct 21, 2019 at 20:02
  • Try adding the IPv6 entry (the IPv6 equivalent of 127.0.0.1 is ::1, so use "::1 www.youtube.com") and see if that blocks it. Commented Oct 21, 2019 at 20:03
  • Used it, it doesn't. The restriction works when i type it as an url, but when clicking from google, it doesn't work.
    – kamran1124
    Commented Oct 21, 2019 at 20:08
  • I wonder if it has to do with Google sending all clicks through their ad tracking network before it gets to youtube itself. It doesn't make sense that it would but if you Google youtube and click on the link you should notice a really fast redirect before it hits youtube. Commented Oct 22, 2019 at 12:45

1 Answer 1

4
  1. Edit your hosts file:
sudo vi /etc/hosts
  1. Add URLs you want to block. This should be sufficient:
# Block YouTube
127.0.0.1 youtube.com
127.0.0.1 www.youtube.com
127.0.0.1 youtu.be
127.0.0.1 www.youtu.be
127.0.0.1 youtube-nocookie.com
127.0.0.1 www.youtube-nocookie.com
  1. Reset the Directory Service cache
dscacheutil -flushcache
  1. Ping the the hosts for verification:
$ ping youtube.com    
PING youtube.com (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.048 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.100 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.088 ms

$ ping youtu.be
PING youtu.be (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.049 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.151 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.082 ms

If you still can access the site, a reboot should help.

sudo reboot
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .