Community discussions

MikroTik App
 
User avatar
Shahid
newbie
Topic Author
Posts: 27
Joined: Sat Nov 05, 2016 3:31 am
Location: Multan, Pakistan
Contact:

How to block YouTube effectively

Mon Apr 29, 2024 2:56 am

I need to block YouTube as much as possible to minimize access to the platform.
Could you please share the most effective method to achieve this?
Currently, I'm using Layer 7 filtering to block YouTube's DNS, but I'm looking for additional measures to reinforce this blockage and prevent users from finding workarounds.
/ip firewall layer7-protocol
add name=YouTube regexp="^.+(youtube.com|googlevideo.com|akamaihd.net).*\$"
/ip firewall mangle
add action=mark-connection chain=output comment="YouTube " layer7-protocol=YouTube new-connection-mark=YouTube passthrough=yes
/ip firewall filter
add action=drop chain=output connection-mark=YouTube protocol=udp
Obviously i can add static entry for youtube & googlevideo too.
 
User avatar
BartoszP
Forum Guru
Forum Guru
Posts: 2898
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

Re: How to block YouTube effectively

Mon Apr 29, 2024 8:36 am

check this please: search.php?keywords=block+youtube

You can't do that cheap&easy ... you have to invest a lot of money to do it right.
 
User avatar
GeneralMarmite
just joined
Posts: 17
Joined: Sun Nov 22, 2015 3:03 pm

Re: How to block YouTube effectively

Mon Apr 29, 2024 3:38 pm

I know you're asking how to do this with a Mikrotik router, and I'm about to give you a combination Mikrotik/non-Mikrotik solution. So please forgive me. It is not possible to get all the IP addresses of "youtube.com" and just block them. The layer 7 stuff in the router that you're doing works a little, but it is not robust enough. A layer 7 list in the router is hard to manage and it gets messy quickly the more things you decide you want to block. It's really easy to bypass the layer 7 list in the router using DoH (see step 5 at the end), so you have to do more.

Step 1: Create a local resolver

Get some kind of DNS resolver in your network that is not the router. This is a big step and it's kinda beyond the scope of what I'm writing here. I am a big fan of the pi-hole because I like blocking ads. It also gives you a nice GUI interface for managing DNS block lists and it gives you a database of what domains your network users are visiting. I'll pretend you have installed one and it has IP address 10.0.0.5.

NOTE: The only way to do this reasonably is to create a server of some kind (a VM, a Raspberry Pi, etc.), running software on it, and keeping it alive. It becomes your DNS server for your network, so it is critical infrastructure. If it goes down, end users will say "the internet doesn't work" because DNS can't resolve anything. If you can't or won't run a separate DNS resolver for your network, DNS-based blocking (i.e., blocking based on the "domain name") is not something you'll be able to do (step 5 below explains why).

Step 2: Get your local resolver blocking things

Block domains on your DNS filter. E.g., block youtube.com, googlevideo.com, etc. If you don't want to block ads at the pi-hole, you can turn off the ad blocking features and lists. You just block things named on your manually-curated block list. Ad blocking is pretty pervasive and it can sometimes interfere with normal users' stuff. Half the links they click in Google search are ads. So if they're used to searching the internet by using the world's largest internet advertiser, and then clicking one of the top 5 links, which are all advertisements, they'll discover that these top 5 links don't usually work. It depends on your user population and what's behind this router whether ad blocking will be good, bad, or indifferent.

Now, here's where you can test and try things out without disrupting anyone on your network. On a test system you control, like a laptop, manually configure the DNS and tell it to use 10.0.0.5 (or whatever the IP address of your DNS resolver is). Your test system should browse the internet just fine. If you've enabled ad blocking, that one system should see fewer ads. If you've only blocked a few domains, then try visiting those domains and see that they're blocked. Assuming this one test system is behaving as expected (youtube blocked, everything else working fine), keep going.

In Step 3, you switch all the devices on your network so that they will use the new blocking resolver.

Step 3: Get everyone on the network using the local resolver

Step 3 Variation A: Make sure all your DHCP leases give out your DNS resolver (I'm pretending that's 10.0.0.5) as the DNS server. Assuming your Mikrotik router is your DHCP server, set the DNS server using the right options to
/ip dhcp-server network
. See DHCP documentation). If you do this, the change will take effect gradually, as each device's DHCP lease runs out.

Step 3 Variation B: Instead of (not in addition to) the above, you can give out the router's IP address as the DNS resolver. (This is normal and probably what you do now). Configure the router itself to resolve DNS by going to the pi-hole on 10.0.0.5. E.g.,
/ip dns set servers=10.0.0.5
. You'll do this instead of having your router resolve DNS via the Internet (upstream ISP). If you do this version, the change is essentially instant and affects everyone. So please test before doing this.

Both variations of of Step 3 are reversible. If you mess up, just put it back how it was before.

At this point, lots of devices will find YouTube blocked, but not all. And it's trivial to bypass. In the same way you tested after step 2, someone else can follow those same steps and opt-out of ad blocking/youtube blocking. If they go to their device, change IP their DNS to point to 9.9.9.9 or 1.1.1.1, they will get unfiltered DNS and they'll get YouTube or other blocked domains.

If you really want to make it hard to avoid your filters, the next two steps are where you go back to the Mikrotik and really commit.

Step 4: block any DNS that is not the local resolver

Step 4 A: Impose IP firewall filters that block UDP to port 53 and TCP to port 53 to an IP address except 10.0.0.5 (or whatever DNS server you run). Note that whatever system you choose (e.g. the pi-hole or some other solution) must be exempted from this rule.

In my network I have:
/ip firewall address-list
add address=9.9.9.9 list=allowedDNS
add address=172.30.2.5 list=allowedDNS
add address=172.30.2.1 list=allowedDNS
Then I have firewall rules:
/ip firewall filter
add action=accept chain=forward dst-address-list=allowedDNS dst-port=53 \
    in-interface-list=LAN protocol=udp
add action=accept chain=output comment="Accept TCP 53 to allowable DNS" \
    dst-address-list=allowedDNS dst-port=53 protocol=tcp
add action=accept chain=output comment="Block UDP/53 except allowedDNS" \
    dst-address-list=allowedDNS dst-port=53 protocol=udp
add action=drop chain=output dst-address-list=!allowedDNS dst-port=53 protocol=tcp
Step 4 B: If the source IP is your DNS resolver (e.g., the pi-hole at 10.0.0.5), it must be allowed to connect to any IP address on port 53 either UDP or TCP. The idea here is that the only way to do DNS on your network is to talk to YOUR DNS server. No others will be reachable.

Caution: If you think users on your network may have manually configured DNS somehow, their device will break when you do this. if they have have manually configured DNS (e.g., to use the world's largest internet advertiser 8.8.8.8 or 8.8.4.4), they will find that the internet suddenly doesn't work. Their system will stop resolving DNS names. Until someone manually fixes the device (making it use your local DNS or use DHCP), the device will be unable to use the internet.

Step 5: Try to block some DNS over HTTPS

We're not done. There's a new way of doing DNS, however, called DNS over HTTP (DoH). Frankly, this is pretty hard to block. The clients will make outbound HTTPS connections on port 443 to some well-known services that provide DNS. Chrome does this by default. This means that when the browser tries to look up "www.youtube.com" it will make an HTTPS connection to a well known cloudflare server (or other server) and it will get the DNS answer. You'll need to block some new domains, just to block DNS over HTTPS. Go back to your pi-hole or whatever DNS resolver you're using for blocking and block at least these 3 domains.
At this point, you've done a lot. Only the craftiest people will be able to get around this. It's not bulletproof. I'm sure there are public DoH servers out there other than CloudFlare and Google. If one of your users figures out how to configure their browser to use that DoH resolver, they'll be able to watch YouTube. There are probably some other bypasses possible. But this raises the bar a lot. It will block a lot of YouTube for ordinary users.

Conclusion

This will block a lot of stuff. it's not perfect. There is no perfect solution. It really depends on who your users are, how hard they will try, and how bad it is if they succeed as to how much work you want to put into making it harder and harder.
 
User avatar
vingjfg
Member
Member
Posts: 344
Joined: Fri Oct 20, 2023 1:45 pm

Re: How to block YouTube effectively

Mon Apr 29, 2024 4:54 pm

You can also use the TLS Host to reset the connections to the sites you don't want.

https://mum.mikrotik.com/presentations/ ... 535774.pdf
 
User avatar
Larsa
Forum Guru
Forum Guru
Posts: 1106
Joined: Sat Aug 29, 2015 7:40 pm
Location: The North Pole, Santa's Workshop

Re: How to block YouTube effectively

Mon Apr 29, 2024 5:03 pm

Nowadays, even the SNI field (TLS Host) is often encrypted using ESNI encryption.
 
User avatar
Shahid
newbie
Topic Author
Posts: 27
Joined: Sat Nov 05, 2016 3:31 am
Location: Multan, Pakistan
Contact:

Re: How to block YouTube effectively

Mon Apr 29, 2024 10:14 pm

Step 1: Create a local resolver

Get some kind of DNS resolver in your network that is not the router. This is a big step and it's kinda beyond the scope of what I'm writing here. I am a big fan of the pi-hole because I like blocking ads. It also gives you a nice GUI interface for managing DNS block lists and it gives you a database of what domains your network users are visiting. I'll pretend you have installed one and it has IP address 10.0.0.5.
Setting up a Pi-hole server in a Docker container within a Mikrotik router is a brilliant idea.
I have previously used Pi-hole in a container for ad-blocking and was impressed with its effectiveness.
I appreciate your approach and am grateful for the time you've taken to share your expertise.
I'll definitely try out your proposal and post the results, so others can benefit from my experience as well.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10282
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to block YouTube effectively

Mon Apr 29, 2024 11:01 pm

Nowadays, even the SNI field (TLS Host) is often encrypted using ESNI encryption.
And Youtube runs over UDP when possible, which "TLS host" does not support.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10282
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to block YouTube effectively

Mon Apr 29, 2024 11:02 pm

This will block a lot of stuff. it's not perfect. There is no perfect solution. It really depends on who your users are, how hard they will try, and how bad it is if they succeed as to how much work you want to put into making it harder and harder.
When you have users that even have the slightest motivation to try, they will walk around your solutions without difficulty!
 
jollyrogr
just joined
Posts: 14
Joined: Sun Apr 21, 2024 10:31 pm

Re: How to block YouTube effectively

Mon Apr 29, 2024 11:11 pm

I know you're asking how to do this with a Mikrotik router, and I'm about to give you a combination Mikrotik/non-Mikrotik solution. So please forgive me. It is not possible to get all the IP addresses of "youtube.com" and just block them. The layer 7 stuff in the router that you're doing works a little, but it is not robust enough. A layer 7 list in the router is hard to manage and it gets messy quickly the more things you decide you want to block. It's really easy to bypass the layer 7 list in the router using DoH (see step 5 at the end), so you have to do more.

Step 1: Create a local resolver

Get some kind of DNS resolver in your network that is not the router. This is a big step and it's kinda beyond the scope of what I'm writing here. I am a big fan of the pi-hole because I like blocking ads. It also gives you a nice GUI interface for managing DNS block lists and it gives you a database of what domains your network users are visiting. I'll pretend you have installed one and it has IP address 10.0.0.5.

NOTE: The only way to do this reasonably is to create a server of some kind (a VM, a Raspberry Pi, etc.), running software on it, and keeping it alive. It becomes your DNS server for your network, so it is critical infrastructure. If it goes down, end users will say "the internet doesn't work" because DNS can't resolve anything. If you can't or won't run a separate DNS resolver for your network, DNS-based blocking (i.e., blocking based on the "domain name") is not something you'll be able to do (step 5 below explains why).

Step 2: Get your local resolver blocking things

Block domains on your DNS filter. E.g., block youtube.com, googlevideo.com, etc. If you don't want to block ads at the pi-hole, you can turn off the ad blocking features and lists. You just block things named on your manually-curated block list. Ad blocking is pretty pervasive and it can sometimes interfere with normal users' stuff. Half the links they click in Google search are ads. So if they're used to searching the internet by using the world's largest internet advertiser, and then clicking one of the top 5 links, which are all advertisements, they'll discover that these top 5 links don't usually work. It depends on your user population and what's behind this router whether ad blocking will be good, bad, or indifferent.

Now, here's where you can test and try things out without disrupting anyone on your network. On a test system you control, like a laptop, manually configure the DNS and tell it to use 10.0.0.5 (or whatever the IP address of your DNS resolver is). Your test system should browse the internet just fine. If you've enabled ad blocking, that one system should see fewer ads. If you've only blocked a few domains, then try visiting those domains and see that they're blocked. Assuming this one test system is behaving as expected (youtube blocked, everything else working fine), keep going.

In Step 3, you switch all the devices on your network so that they will use the new blocking resolver.

Step 3: Get everyone on the network using the local resolver

Step 3 Variation A: Make sure all your DHCP leases give out your DNS resolver (I'm pretending that's 10.0.0.5) as the DNS server. Assuming your Mikrotik router is your DHCP server, set the DNS server using the right options to
/ip dhcp-server network
. See DHCP documentation). If you do this, the change will take effect gradually, as each device's DHCP lease runs out.

Step 3 Variation B: Instead of (not in addition to) the above, you can give out the router's IP address as the DNS resolver. (This is normal and probably what you do now). Configure the router itself to resolve DNS by going to the pi-hole on 10.0.0.5. E.g.,
/ip dns set servers=10.0.0.5
. You'll do this instead of having your router resolve DNS via the Internet (upstream ISP). If you do this version, the change is essentially instant and affects everyone. So please test before doing this.

Both variations of of Step 3 are reversible. If you mess up, just put it back how it was before.

At this point, lots of devices will find YouTube blocked, but not all. And it's trivial to bypass. In the same way you tested after step 2, someone else can follow those same steps and opt-out of ad blocking/youtube blocking. If they go to their device, change IP their DNS to point to 9.9.9.9 or 1.1.1.1, they will get unfiltered DNS and they'll get YouTube or other blocked domains.

If you really want to make it hard to avoid your filters, the next two steps are where you go back to the Mikrotik and really commit.

Step 4: block any DNS that is not the local resolver

Step 4 A: Impose IP firewall filters that block UDP to port 53 and TCP to port 53 to an IP address except 10.0.0.5 (or whatever DNS server you run). Note that whatever system you choose (e.g. the pi-hole or some other solution) must be exempted from this rule.

In my network I have:
/ip firewall address-list
add address=9.9.9.9 list=allowedDNS
add address=172.30.2.5 list=allowedDNS
add address=172.30.2.1 list=allowedDNS
Then I have firewall rules:
/ip firewall filter
add action=accept chain=forward dst-address-list=allowedDNS dst-port=53 \
    in-interface-list=LAN protocol=udp
add action=accept chain=output comment="Accept TCP 53 to allowable DNS" \
    dst-address-list=allowedDNS dst-port=53 protocol=tcp
add action=accept chain=output comment="Block UDP/53 except allowedDNS" \
    dst-address-list=allowedDNS dst-port=53 protocol=udp
add action=drop chain=output dst-address-list=!allowedDNS dst-port=53 protocol=tcp
Step 4 B: If the source IP is your DNS resolver (e.g., the pi-hole at 10.0.0.5), it must be allowed to connect to any IP address on port 53 either UDP or TCP. The idea here is that the only way to do DNS on your network is to talk to YOUR DNS server. No others will be reachable.

Caution: If you think users on your network may have manually configured DNS somehow, their device will break when you do this. if they have have manually configured DNS (e.g., to use the world's largest internet advertiser 8.8.8.8 or 8.8.4.4), they will find that the internet suddenly doesn't work. Their system will stop resolving DNS names. Until someone manually fixes the device (making it use your local DNS or use DHCP), the device will be unable to use the internet.

Step 5: Try to block some DNS over HTTPS

We're not done. There's a new way of doing DNS, however, called DNS over HTTP (DoH). Frankly, this is pretty hard to block. The clients will make outbound HTTPS connections on port 443 to some well-known services that provide DNS. Chrome does this by default. This means that when the browser tries to look up "www.youtube.com" it will make an HTTPS connection to a well known cloudflare server (or other server) and it will get the DNS answer. You'll need to block some new domains, just to block DNS over HTTPS. Go back to your pi-hole or whatever DNS resolver you're using for blocking and block at least these 3 domains.
At this point, you've done a lot. Only the craftiest people will be able to get around this. It's not bulletproof. I'm sure there are public DoH servers out there other than CloudFlare and Google. If one of your users figures out how to configure their browser to use that DoH resolver, they'll be able to watch YouTube. There are probably some other bypasses possible. But this raises the bar a lot. It will block a lot of YouTube for ordinary users.

Conclusion

This will block a lot of stuff. it's not perfect. There is no perfect solution. It really depends on who your users are, how hard they will try, and how bad it is if they succeed as to how much work you want to put into making it harder and harder.

Good info. I use pihole to block youtube on my network as well, but my pihole servers use unbound so they are not querying external DNS servers. Does that mean I can block all traffic on port 53 on my firewall and what does that look like? Thanks.
 
User avatar
Larsa
Forum Guru
Forum Guru
Posts: 1106
Joined: Sat Aug 29, 2015 7:40 pm
Location: The North Pole, Santa's Workshop

Re: How to block YouTube effectively

Mon Apr 29, 2024 11:52 pm

And Youtube runs over UDP when possible, which "TLS host" does not support.

Well yes, sort of. ;-) It all depends on the video source and whether you're using the HTML5 video player which supports several streaming protocols such as HLS, RTMP/RTMPS, and DASH. For example, MPEG-DASH (high-res) and HLS use TCP, whereas UDP is used for HTTP/3 QUIC streams and RTMP which is the most commonly used protocol on YouTube.
 
Kindis
Member
Member
Posts: 438
Joined: Tue Nov 01, 2011 6:54 pm
Location: Sweden

Re: How to block YouTube effectively

Tue Apr 30, 2024 12:58 am

I use NextDNS for all this. Means I do not have to manage the dns and it's setting myself.
So I point all Dhcp to NextDNS and also perform dstnat on any port 53 traffik that is not going to NextDNS so that goes to NextDNS.
Work very well for my setup at least.
 
User avatar
GeneralMarmite
just joined
Posts: 17
Joined: Sun Nov 22, 2015 3:03 pm

Re: How to block YouTube effectively

Tue Apr 30, 2024 1:14 am

Good info. I use pihole to block youtube on my network as well, but my pihole servers use unbound so they are not querying external DNS servers. Does that mean I can block all traffic on port 53 on my firewall and what does that look like? Thanks.
Unbound is the name of the software your servers run, not the name of servers that they query. Your unbound servers don't have the entire world's database of IP/name mappings installed. If they are actually able to resolve names to IP addresses, they are definitely querying outside servers. They might not be querying the recursive resolvers that your ISP assigns to you, but they are definitely querying SOMEBODY. Here is a super primitive diagram that kinda shows what happens (a) when your laptop needs to know the IP address of www.youtube.com, (b) it asks your PiHole, and (c) the PiHole has nothing cached, so it has to query everything, and (d) everything works normally as expected. In reality it's much more complicated, but this gets the idea across.
dns-recursion.png
Now, most people don't have a PiHole, so if you're reading this and wondering how it works in YOUR network, since you don't have a PiHole, just change the label from "PiHole" to something else. It might be "Mikrotik Router" in the 'PiHole' column, if your router does DNS resolution for your network. Or it might be "My ISP's DNS server" instead of "PiHole" if you use the DNS server your ISP assigns. Something, somewhere in your network, acts as a "recursive resolver" to do all the chasing of records I showed in that diagram.
You do not have the required permissions to view the files attached to this post.
 
User avatar
GeneralMarmite
just joined
Posts: 17
Joined: Sun Nov 22, 2015 3:03 pm

Re: How to block YouTube effectively

Tue Apr 30, 2024 1:48 am

Nowadays, even the SNI field (TLS Host) is often encrypted using ESNI encryption.
And Youtube runs over UDP when possible, which "TLS host" does not support.
YouTube at most delivers the video stream via UDP after you've found the video you want to watch and started playing it. If you can't get the video stream started because you can't reach YouTube's web interface to search and click on things, you won't get to the part of the process where UDP gets involved. You can't start a video using only UDP. You can't search for videos using only UDP. So the fact that some of the packets really late in the conversation are delivered via UDP, which could not be blocked by these DNS/TCP-focused approaches, is irrelevant.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10282
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to block YouTube effectively

Tue Apr 30, 2024 12:11 pm

That is only until Youtube have migrated their entire website to QUIC.
 
jollyrogr
just joined
Posts: 14
Joined: Sun Apr 21, 2024 10:31 pm

Re: How to block YouTube effectively

Wed May 01, 2024 6:59 am

Good info. I use pihole to block youtube on my network as well, but my pihole servers use unbound so they are not querying external DNS servers. Does that mean I can block all traffic on port 53 on my firewall and what does that look like? Thanks.
Unbound is the name of the software your servers run, not the name of servers that they query. Your unbound servers don't have the entire world's database of IP/name mappings installed. If they are actually able to resolve names to IP addresses, they are definitely querying outside servers. They might not be querying the recursive resolvers that your ISP assigns to you, but they are definitely querying SOMEBODY. Here is a super primitive diagram that kinda shows what happens (a) when your laptop needs to know the IP address of www.youtube.com, (b) it asks your PiHole, and (c) the PiHole has nothing cached, so it has to query everything, and (d) everything works normally as expected. In reality it's much more complicated, but this gets the idea across.
dns-recursion.png

Now, most people don't have a PiHole, so if you're reading this and wondering how it works in YOUR network, since you don't have a PiHole, just change the label from "PiHole" to something else. It might be "Mikrotik Router" in the 'PiHole' column, if your router does DNS resolution for your network. Or it might be "My ISP's DNS server" instead of "PiHole" if you use the DNS server your ISP assigns. Something, somewhere in your network, acts as a "recursive resolver" to do all the chasing of records I showed in that diagram.
I get that, but if unbound isn't using port 53, I can block it on my firewall and prevent users on my network from bypassing my piholes, right?
 
User avatar
GeneralMarmite
just joined
Posts: 17
Joined: Sun Nov 22, 2015 3:03 pm

Re: How to block YouTube effectively

Wed May 01, 2024 3:57 pm

I get that, but if unbound isn't using port 53, I can block it on my firewall and prevent users on my network from bypassing my piholes, right?
How is unbound getting its DNS data? DNS-over-HTTPS (DoH)? Sure, if unbound somehow gets its information without using port 53 and you want to make sure nobody else uses port 53 either, you can block that port.

Blocking DoH, though, is harder. It's a bit of whack-a-mole. You can block the well-known ones (Cloudflare, Google, etc.) but there are an infinite number of smaller ones. It's all about how much effort you want to go to and how hard you think people are willing to work to bypass your controls. But yeah, you can block port 53 and 953 (DNS over TCP) and prevent most people from resolving any way other than your pi-hole.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10282
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to block YouTube effectively

Wed May 01, 2024 4:22 pm

Also, when the viewers have been on Youtube before they will remember the countless ads for VPN services they have seen there.
So they will install one of those and your Youtube Block Attempt will turn into a VPN Block hunt.
 
jollyrogr
just joined
Posts: 14
Joined: Sun Apr 21, 2024 10:31 pm

Re: How to block YouTube effectively

Wed May 01, 2024 4:58 pm

I get that, but if unbound isn't using port 53, I can block it on my firewall and prevent users on my network from bypassing my piholes, right?
How is unbound getting its DNS data?
That's what I'm trying to understand. Not sure what port it uses by default.
 
User avatar
vingjfg
Member
Member
Posts: 344
Joined: Fri Oct 20, 2023 1:45 pm

Re: How to block YouTube effectively

Wed May 01, 2024 5:05 pm

There are some defaults that can be selected during the install. From the page:
Google
OpenDNS
Level3
Comodo
DNS.WATCH
Quad9
CloudFlare DNS
Custom
 
CGGXANNX
Member Candidate
Member Candidate
Posts: 122
Joined: Thu Dec 21, 2023 6:45 pm

Re: How to block YouTube effectively

Wed May 01, 2024 9:13 pm

YouTube at most delivers the video stream via UDP after you've found the video you want to watch and started playing it. If you can't get the video stream started because you can't reach YouTube's web interface to search and click on things, you won't get to the part of the process where UDP gets involved. You can't start a video using only UDP. You can't search for videos using only UDP. So the fact that some of the packets really late in the conversation are delivered via UDP, which could not be blocked by these DNS/TCP-focused approaches, is irrelevant.

Your info are outdated. Look at this Protocol column when loading the front page of YouTube (and see document/text/html on the Type column beside it).

youtube-h3.png

Now, do you know what transport layer HTTP/3 relies on?
You do not have the required permissions to view the files attached to this post.
 
CGGXANNX
Member Candidate
Member Candidate
Posts: 122
Joined: Thu Dec 21, 2023 6:45 pm

Re: How to block YouTube effectively

Wed May 01, 2024 9:41 pm


How is unbound getting its DNS data?
That's what I'm trying to understand. Not sure what port it uses by default.
By default, it works as a caching recursive resolver, which means it will query the root servers, etc... and use port 53 (UDP & TCP). It can also work as forwarder and forwards requests to upstream DNS servers. In that case, DoT (DNS over TLS) can also be used and unbound will use port 853 TCP to communicate with the upstream servers (or other custom ports that those servers might support).
 
jollyrogr
just joined
Posts: 14
Joined: Sun Apr 21, 2024 10:31 pm

Re: How to block YouTube effectively

Thu May 02, 2024 3:55 pm



That's what I'm trying to understand. Not sure what port it uses by default.
By default, it works as a caching recursive resolver, which means it will query the root servers, etc... and use port 53 (UDP & TCP). It can also work as forwarder and forwards requests to upstream DNS servers. In that case, DoT (DNS over TLS) can also be used and unbound will use port 853 TCP to communicate with the upstream servers (or other custom ports that those servers might support).
Thanks. Can confirm that the root server queries are on port 53. So for now I have 53 blocked on my firewall for everybody except the piholes.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10282
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to block YouTube effectively

Thu May 02, 2024 4:06 pm

Thanks. Can confirm that the root server queries are on port 53. So for now I have 53 blocked on my firewall for everybody except the piholes.
That is fine, as long as you understand that in today's world that does not do anything.
(because of DoT, DoH and VPN)
 
jollyrogr
just joined
Posts: 14
Joined: Sun Apr 21, 2024 10:31 pm

Re: How to block YouTube effectively

Thu May 02, 2024 4:22 pm

That is fine, as long as you understand that in today's world that does not do anything.
(because of DoT, DoH and VPN)
I'm preventing my kids from going around the block by trying to use another DNS server. As of now they don't even know how I'm blocking them. If they were to figure it out and try the options you've listed, I'll shut off their internet on the firewall.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10282
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to block YouTube effectively

Thu May 02, 2024 4:35 pm

When your kids have Google software (Android, Chrome) they already are using DoH without knowing it...
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19674
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: How to block YouTube effectively

Thu May 02, 2024 4:48 pm

Education is what you need, MT wont replace parenting.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10282
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to block YouTube effectively

Fri May 03, 2024 3:35 pm

Besides that, there are a lot of very educational videos on Youtube.
E.g. on the MikroTik channel :-)
https://www.youtube.com/@mikrotik
 
User avatar
GeneralMarmite
just joined
Posts: 17
Joined: Sun Nov 22, 2015 3:03 pm

Re: How to block YouTube effectively

Sat May 04, 2024 12:50 am

Your info are outdated. Look at this Protocol column when loading the front page of YouTube (and see document/text/html on the Type column beside it).

Now, do you know what transport layer HTTP/3 relies on?
I get that. That is news to me a little bit, but I don't understand how it is relevant. That browser is doing UDP connections to youtube. How did the browser resolve youtube.com to an IP address to initiate that UDP stream? If the DNS blocking works and the browser cannot resolve the name youtube.com to a valid IP address, I don't see how the browser makes an HTTP/3 connection via UDP. Assuming the person uses some technology (DoH, VPN, etc.) to bypass the DNS blocking tricks, which means they can resolve the name youtube.com to a valid IP, they'll be able to use HTTP/3 or just good old HTTP/2.

There isn't a situation where HTTP/2 is blocked but HTTP/3 works, is there? Either DNS blocking works and neither HTTP/2 nor HTTP/3 work, or DNS blocking is bypassed and both HTTP/2 and HTTP/3 work fine. What am I missing?
 
CGGXANNX
Member Candidate
Member Candidate
Posts: 122
Joined: Thu Dec 21, 2023 6:45 pm

Re: How to block YouTube effectively

Sat May 04, 2024 6:39 am

I get that. That is news to me a little bit, but I don't understand how it is relevant. That browser is doing UDP connections to youtube. How did the browser resolve youtube.com to an IP address to initiate that UDP stream? If the DNS blocking works and the browser cannot resolve the name youtube.com to a valid IP address, I don't see how the browser makes an HTTP/3 connection via UDP. Assuming the person uses some technology (DoH, VPN, etc.) to bypass the DNS blocking tricks, which means they can resolve the name youtube.com to a valid IP, they'll be able to use HTTP/3 or just good old HTTP/2.

There isn't a situation where HTTP/2 is blocked but HTTP/3 works, is there? Either DNS blocking works and neither HTTP/2 nor HTTP/3 work, or DNS blocking is bypassed and both HTTP/2 and HTTP/3 work fine. What am I missing?

It's now very easy to have secure DNS turned on. Mobile OSes have settings to turn them on at the OS level, same with Windows. Every modern web browser now either use secure DNS by default or have setting to turn that on. So, you just have to assume that DNS blocking is useless against someone who know how to use the search engine for two minutes.

As for why UDP and HTTP/3 are relevant. As other have posted in the thread. With HTTP/2 and without ECH (encrypted client hello) support from the sites, it was until recently possible, with helps from the requirement for SNI, to "block" traffic to sites using HTTPS and HTTP/2 by using the tls-host filter. Because in the first packets of the HTTPS connection the domain name is sent in clear text. But that feature from RouterOS only supports TCP and older HTTP protocols. HTTP/3 uses QUIC (over UDP) and also with ECH the domain name is no longer sent in clear text.

So, with secure DNS and HTTP/3, there is no way for you on the router running RouterOS to know whether someone in your LAN is opening YouTube anymore. Unless you somehow have the list of all possible IP addresses used by Google to serve the site and its videos.

If a site supports both HTTP/2 and HTTP/3, even if you successfully identify and block the HTTP/2 connection to it, eventually the users will still be able to access the sites. Because nowadays, to profit from the latency advantages that HTTP/3 brings immediately, even when visiting a brand-new site, browsers will try to establish both connections, TCP for HTTP/2 and QUIC for HTTP/3 at the same time. And if HTTP/3 "wins" (because of lower latency) the browsers will switch to using it immediately and don't even wait for the HTTP/2 connection to complete. Here you can see my browser (Edge) says that it switches to using HTTP/3 because it won the race when I tried to access medium.com

medium.png

Also, last November RFC 9460 has became "Proposed Standard". With this (HTTPS Resource Record in DNS) sites are now able to instruct browsers to always use HTTP/3, there is no need to initiate the parallel HTTP/2 connection. Modern browsers currently already query for RR type 65 (HTTPS RR) when looking up the domain with DNS, and CDN like Cloudflare already enable the records when the hosted site support HTTP/3. Here you can see apln="h3,h2" in the HTTPS record as an example.

https-rr.png
You do not have the required permissions to view the files attached to this post.
 
User avatar
Zilch
just joined
Posts: 11
Joined: Mon Mar 25, 2024 6:11 pm
Location: Kaapstad

Re: How to block YouTube effectively

Sat May 04, 2024 2:17 pm

The best way for blocking sites - at least from the results I have been able to accomplish - is as follows.

1) Find all domain names related to a service. This requires some manual input from the user, but there are blocklists on Github. Netify.ai is also very useful.

2) Add all those domain names to an address list. This is easiest when done through the terminal. For example...
/ip firewall address-list

add address="googlevideo.com" comment="YouTube" list="Blocked Domains"
add address="gvt1.com" comment="YouTube" list="Blocked Domains"
add address="video.google.com" comment="YouTube" list="Blocked Domains"
add address="video.l.google.com" comment="YouTube" list="Blocked Domains"
add address="youtu.be" comment="YouTube" list="Blocked Domains"
add address="youtube.com" comment="YouTube" list="Blocked Domains"
add address="m.youtube.com" comment="YouTube" list="Blocked Domains"
add address="www.youtube.com" comment="YouTube" list="Blocked Domains"
add address="youtubeeducation.com" comment="YouTube" list="Blocked Domains"
add address="youtubeembeddedplayer.googleapis.com" comment="YouTube" list="Blocked Domains"
add address="youtube.googleapis.com" comment="YouTube" list="Blocked Domains"
add address="youtubei.googleapis.com" comment="YouTube" list="Blocked Domains"
add address="youtubekids.com" comment="YouTube" list="Blocked Domains"
add address="youtube-nocookie.com" comment="YouTube" list="Blocked Domains"
add address="youtube-ui.l.google.com" comment="YouTube" list="Blocked Domains"
add address="yt3.ggpht.com" comment="YouTube" list="Blocked Domains"
add address="yt.be" comment="YouTube" list="Blocked Domains"
add address="ytimg.com" comment="YouTube" list="Blocked Domains"
add address="ytimg.l.google.com" comment="YouTube" list="Blocked Domains"
add address="ytkids.app.goo.gl" comment="YouTube" list="Blocked Domains"
add address="yt-video-upload.l.google.com" comment="YouTube" list="Blocked Domains"
add address="l.google.com" comment="YouTube" list="Blocked Domains"
add address="i.google.com" comment="YouTube" list="Blocked Domains"
add address="s.ytimg.com" comment="YouTube" list="Blocked Domains"
add address="withyoutube.com" comment="YouTube" list="Blocked Domains"
add address="wide-youtube.l.google.com" comment="YouTube" list="Blocked Domains"
add address="ggpht.com" comment="YouTube" list="Blocked Domains"
add address="youtubefanfest.com" comment="YouTube" list="Blocked Domains"
add address="youtubegaming.com" comment="YouTube" list="Blocked Domains"
add address="youtubego.com" comment="YouTube" list="Blocked Domains"
add address="youtubemobilesupport.com" comment="YouTube" list="Blocked Domains"

3) Next add two firewall rules. One looks at the IP addresses and adds it to a list with a TTL of 30 days. Remember to move it to the correct position/number after adding it.
/ip firewall filter

add chain="forward" dst-address-list="Blocked Domains" action="add-dst-to-address-list" address-list="Blocked Domain IPs" address-list-timeout="30d 00:00:00"
add chain="forward" dst-address-list="Blocked Domain IPs" action="drop"

4) Make sure your MikroTik's DNS server accepts external queries (while also blocking queries from WAN!) and use it in your DHCP Server. This is important because if the client device requests the IP of 'youtube.com', and it goes through the MikroTik, the firewall will memorise the IPs and it will work very effectively! My DNS config is as follows...
[admin@MikroTik] > /ip dns print
                      servers: 1.1.1.1,1.0.0.1,8.8.8.8,8.8.4.4
              dynamic-servers: 
               use-doh-server: 
              verify-doh-cert: no
   doh-max-server-connections: 5
   doh-max-concurrent-queries: 50
                  doh-timeout: 5s
        allow-remote-requests: yes
          max-udp-packet-size: 4096
         query-server-timeout: 2s
          query-total-timeout: 10s
       max-concurrent-queries: 1000
  max-concurrent-tcp-sessions: 100
                   cache-size: 32768KiB
                cache-max-ttl: 1d
      address-list-extra-time: 0s
                   cache-used: 58KiB
Last edited by Zilch on Sat May 04, 2024 2:28 pm, edited 1 time in total.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10282
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to block YouTube effectively

Sat May 04, 2024 2:27 pm

The reason that this does not work well is that there are multiple addresses for each domain name, and that the returned addresses vary depending on where the DNS request is coming from.
When your router is making DNS requests for these domains via the DNS resolvers configured in the router, it can get different addresses than the user gets via the 8.8.8.8 or 9.9.9.9 or whatever resolver they use in their phone!
 
User avatar
Zilch
just joined
Posts: 11
Joined: Mon Mar 25, 2024 6:11 pm
Location: Kaapstad

Re: How to block YouTube effectively

Sat May 04, 2024 2:31 pm

@pe1chl indeed, realized my mistake. I quickly edited my post just before seeing yours.
 
User avatar
GeneralMarmite
just joined
Posts: 17
Joined: Sun Nov 22, 2015 3:03 pm

Re: How to block YouTube effectively

Sat May 04, 2024 9:52 pm

It's now very easy to have secure DNS turned on. Mobile OSes have settings to turn them on at the OS level, same with Windows. Every modern web browser now either use secure DNS by default or have setting to turn that on. So, you just have to assume that DNS blocking is useless against someone who know how to use the search engine for two minutes.
.

Ok. that's the issue. You're assuming DNS blocking is trivially bypassed. Because none of the things you mention are relevant if DNS blocking works. SNI, ECH, QUIC, etc. all require DNS first to look up the IP to talk to.

I don't see any network-level way of blocking a web site, given just its domain name, like youtube.com. That was how I opened the discussion. There's no practical way to block the IP addresses, to block ports, no SNI inspection, etc. That's why I started with talking about how to block DNS resolution for a domain, highlighting all the ways that it has limitations. Everyone seems to have piled in to point out all the ways that DNS blocking can be bypassed, which are all true, but that doesn't yield any practical result for the OP. I'm going to focus on making it hard to bypass DNS blocking.
 
optio
Long time Member
Long time Member
Posts: 696
Joined: Mon Dec 26, 2022 2:57 pm

Re: How to block YouTube effectively

Sun May 05, 2024 2:47 am

DNS blocking can be trivially bypassed by putting resolved IP addresses for blocked hosts into OS hosts file.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3307
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: How to block YouTube effectively

Sun May 05, 2024 8:18 am

I need to block YouTube as much as possible to minimize access to the platform.
Why?
 
User avatar
Zilch
just joined
Posts: 11
Joined: Mon Mar 25, 2024 6:11 pm
Location: Kaapstad

Re: How to block YouTube effectively

Sun May 05, 2024 10:46 am

I need to block YouTube as much as possible to minimize access to the platform.
Why?
Some business users with limited bandwidth do not want their WAN interface saturated. I have seen this for some businesses with only 15mbps.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10282
Joined: Mon Jun 08, 2015 12:09 pm

Re: How to block YouTube effectively

Sun May 05, 2024 12:04 pm

That will be an endless uphill battle.
When you are selling such a limited service (or your clients buy it and ask you to maintain the router) you should simply explain to them that it has limited usefulness in today's world, and that it will easily be saturated.
And tell them that their policy should be "no video streaming or other high-bandwidth applications".

"blocking youtube" is not going to bring you anything. there are plenty other video services and you cannot block all of them.
instead, maybe focus on some queueing setup so that high-bandwitdh users do not adversely affect low-latency users (like VoIP).
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3307
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: How to block YouTube effectively

Mon May 06, 2024 3:12 pm

I do 100% agree to pe1chl

If you have limited bandwidth, I would use some QoS.
Example if you have 10MBps total and 4 users, you could give 2.5MBps to all 4.
If some of the 4 does not use all their bandwidth, you can share it with the rest or the one who needs more.

Edit, if this is for children, then its education.

Who is online

Users browsing this forum: Amazon [Bot], holvoetn, mkx and 21 guests