Firewall

How to Block Facebook and YouTube on MikroTik (RouterOS v7)

Block Facebook, YouTube or any HTTPS website on a MikroTik router with the TLS host matcher and a QUIC rule, only for the users you choose.

Commands in this article follow RouterOS v7 documentation but have not yet been marked as lab-tested on this site. Always test changes in a lab or maintenance window and keep a backup.

Problem

You need to block Facebook, YouTube or another website for some users, for example in an office or a school lab. Blocking IP addresses or using Layer 7 rules does not work well, because these sites use HTTPS and change IP addresses constantly.

Symptoms

  • Blocking a website's IP address stops working after a few hours.
  • Layer 7 rules do not block HTTPS sites and push CPU usage up.

Likely causes

Modern websites use HTTPS (TLS) and QUIC (HTTP/3 on UDP port 443) and are served from large CDNs. The router cannot see the full URL, but it can see the server name (SNI) in the TLS handshake. RouterOS matches this with tls-host.

Prerequisites

  • RouterOS v6.41 or later (v7 recommended).
  • The users you want to block, for example 192.168.88.0/24.
  • A backup: /export file=before-block.

Solution (WinBox / CLI)

1. Put the users in an address list (or use your whole LAN):

RouterOS CLI
/ip firewall address-list add list=blocked-users address=192.168.88.0/24

2. Keep these users out of FastTrack. The server name is sent after the TCP connection is established. If the connection is already fasttracked, the firewall never sees it:

RouterOS CLI
/ip firewall filter set [find action=fasttrack-connection] src-address-list=!blocked-users dst-address-list=!blocked-users

3. Block the server names. Use place-before=0 so the rules sit at the top of the forward chain:

RouterOS CLI
/ip firewall filter
add chain=forward src-address-list=blocked-users protocol=tcp dst-port=443 tls-host=facebook.com action=reject reject-with=tcp-reset comment="Block social" place-before=0
add chain=forward src-address-list=blocked-users protocol=tcp dst-port=443 tls-host=*.facebook.com action=reject reject-with=tcp-reset comment="Block social" place-before=0
add chain=forward src-address-list=blocked-users protocol=tcp dst-port=443 tls-host=*.fbcdn.net action=reject reject-with=tcp-reset comment="Block social" place-before=0
add chain=forward src-address-list=blocked-users protocol=tcp dst-port=443 tls-host=youtube.com action=reject reject-with=tcp-reset comment="Block social" place-before=0
add chain=forward src-address-list=blocked-users protocol=tcp dst-port=443 tls-host=*.youtube.com action=reject reject-with=tcp-reset comment="Block social" place-before=0
add chain=forward src-address-list=blocked-users protocol=tcp dst-port=443 tls-host=*.googlevideo.com action=reject reject-with=tcp-reset comment="Block social" place-before=0

4. Block QUIC for the same users. Browsers then fall back to normal HTTPS, which the rules above can see:

RouterOS CLI
/ip firewall filter add chain=forward src-address-list=blocked-users protocol=udp dst-port=443 action=drop comment="Block QUIC" place-before=0

To block only during office hours, add a time condition such as time=09:00:00-17:00:00,sun,mon,tue,wed,thu to each rule. See Time-based internet rules on MikroTik.

Verification

  • From a blocked PC, open facebook.com. The page should fail to load.
  • Watch the counters grow:
RouterOS CLI
/ip firewall filter print stats where comment~"Block"

Common errors

  • Rules placed below the FastTrack or "accept established" rules: nothing is blocked.
  • QUIC not blocked: YouTube still works in Chrome.
  • Mobile apps use extra domains. Check /ip firewall connection or Torch to find them.
  • Browsers with Encrypted Client Hello (ECH) can hide the server name, so some sites may still open.

Rollback

RouterOS CLI
/ip firewall filter remove [find comment="Block social"]
/ip firewall filter remove [find comment="Block QUIC"]

Then, in WinBox, open the FastTrack rule (IP > Firewall > Filter Rules) and clear the two address-list conditions you added in step 2.

Watch the video: How to block Facebook using MikroTik router

Go deeper in class

This topic is covered hands-on in MTCTCE — MikroTik Certified Traffic Control Engineer.

View MTCTCE
WhatsApp