Block youtube.com

Issues related to configuring your network
Post Reply
User avatar
nicholas5421
Posts: 3
Joined: 2020/01/21 18:32:18
Location: Tel Aviv
Contact:

Block youtube.com

Post by nicholas5421 » 2020/03/03 19:23:25

Hello All,

I am trying to block access to youtube by adding the static record to hosts file.
But i still have youtube access. It seems like the hosts file have been ignored.

Code: Select all

$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
0.0.0.0     youtube.com

Code: Select all

$ ping -c1 youtube.com
PING youtube.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.035 ms

Code: Select all

$ dig youtube.com

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el8 <<>> youtube.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36706
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1452
;; QUESTION SECTION:
;youtube.com.			IN	A

;; ANSWER SECTION:
youtube.com.		257	IN	A	216.58.207.46

;; Query time: 77 msec
;; SERVER: 1.1.1.1#53(1.1.1.1)
;; WHEN: Tue Mar 03 21:19:30 IST 2020
;; MSG SIZE  rcvd: 56
Please help.

sml
Posts: 305
Joined: 2020/01/17 09:01:44

Re: Block youtube.com

Post by sml » 2020/03/04 07:40:30

First, ensure that files comes before anything in your /etc/nsswitch.conf:

Code: Select all

grep ^hosts: /etc/nsswitch.conf
But most probably, it's a DNS caching issue:

Code: Select all

sudo resolvectl flush-caches
DNS lookups may also be cached by another service (dnsmasq, nscd, ...). See How to Flush the DNS Cache on Linux.

Code: Select all

sudo pkill -USR1 dnsmasq
etc.

Try

Code: Select all

grep ^dns= /etc/NetworkManager/NetworkManager.conf
and see if it gives you dns=systemd-resolved or dns=dnsmasq. From Configuring and managing networking:
  • dns=dnsmasq or dns=systemd-resolved:

    When you use one of these settings, NetworkManager sets either 127.0.0.1 for dnsmasq or 127.0.0.53 as nameserver entry in the /etc/resolv.conf file
Last edited by sml on 2020/03/04 08:44:12, edited 4 times in total.

User avatar
TrevorH
Site Admin
Posts: 33216
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Block youtube.com

Post by TrevorH » 2020/03/04 07:43:06

You'll also find that youtube has multiple URLs so blocking youtube.com like that will not also block www.youtube.com or any other variants on that theme.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

User avatar
nicholas5421
Posts: 3
Joined: 2020/01/21 18:32:18
Location: Tel Aviv
Contact:

Re: Block youtube.com

Post by nicholas5421 » 2020/03/04 17:59:18

Thanks, for your help. It seems to be the solution.

In Centos 8, the newer Firefox adds "www" to youtube.com. So there is no any problem.
Also, we could see that configuration worked in my pings.

I will try to block it with firewalld.
Thanks.

matt2020
Posts: 13
Joined: 2020/01/20 07:26:39

Re: Block youtube.com

Post by matt2020 » 2020/03/07 19:11:34

Also remember the latest Firefox is turning on DoH so will be bypassing all local DNS Settings !

https://support.mozilla.org/en-US/kb/fi ... over-https

You may want to turn that Off.

Post Reply