Separate Youtube, Facebook, Internet Bandwidt

To block or monitor YouTube traffic using Layer 7 filtering in MikroTik, you can set up a Layer 7 Protocol rule that matches YouTube-related traffic. This will allow the router to identify traffic directed to YouTube based on domain patterns and take actions such as blocking, logging, or tracking IP addresses.


#=====================================================
# Separate Youtube, Facebook, Internet Bandwidt
#=====================================================

Step-1
1. Go to IP > Firewall > Layer7 Protocols.
2. Click Add (+) to create a new Layer 7 rule.
3. In the Name field, give it a name youtube.
4. In the Regexp field, enter a regex pattern that matches YouTube domains. Here’s a pattern that captures various YouTube-related traffic:
^.*(youtube.com|googlevideo.com|ytimg.com).*

*** This regex pattern includes youtube.com (main site), googlevideo.com (used for serving videos), and ytimg.com (used for YouTube images) ***

Or

/ip firewall layer7-protocol
add name=YouTube regexp="^.*(youtube.com|googlevideo.com|ytimg.com).*"

for Facebook Only
/ip firewall layer7-protocol
add name=Facebook regexp="^.*(facebook.com|fbcdn.net|fb.me|messenger.com|whatsapp.com|instagram.com).*"


Step-2
copy and paste terminal for youtube public address list on firewall address list

/ip firewall address-list add list=youtube address=youtube.com
/ip firewall address-list add list=youtube address=www.youtube.com
/ip firewall address-list add list=youtube address=https://www.youtube.com
/ip firewall address-list add list=youtube address=m.youtube.com
/ip firewall address-list add list=youtube address=https://m.youtube.com
/ip firewall address-list add list=youtube address=youtubei.googleapis.com
/ip firewall address-list add list=youtube address=ttps://youtubei.googleapis.com
/ip firewall address-list add list=youtube address=youtube.googleapis.com
/ip firewall address-list add list=youtube address=https://youtube.googleapis.com
/ip firewall address-list add list=youtube address=www.youtube-nocookie.com



Step-3
/ip firewall filter
add action=add-dst-to-address-list address-list=youtube \
    address-list-timeout=2d chain=forward dst-address-list="!local IP" \
    layer7-protocol=youtube


Step-4
/ip firewall mangle
add action=mark-connection chain=prerouting dst-address-list=youtube \
    new-connection-mark=youtube passthrough=yes
add action=mark-packet chain=prerouting connection-mark=youtube \
    new-packet-mark="youtube packet" passthrough=yes

Step-5
/queue simple
add max-limit=200M/200M name=youtube packet-marks="youtube packet" target=\
    ""