Mikrotik Hotspot, Limit YouTube based on user profile

Last updated on May 28, 2013 @ One Comment

I used to use this limitation on public hotspot. Where everyone free to connect while we’re on limited bandwidth. Video stream usually use high bandwidth, at least 384kbps for SD quality (not HD) and you can imagine if 15 peoples stream YouTube video at the same time while we only have 5MB bandwidth. On busy hours, we got more than 40 public user using our mikrotik hotspot (our highest record 93 users), and most of them are teenagers who connect with their Tablets and MobilePhones.

Just like the earlier posts (Limit number connection, Block per profile), this method use Layer 7 protocol of miktorik firewall and also trapping user ip address. So first we need to add YouTube address into Layer 7 Protocol list. Let’s start.


Add the following to Layer 7 Regexp:


Name it as YouTube-Stream

Regexp Layer 7

Add 1st mangle rule (mark connection)

[General Tab]

  • Chain = prerouting
  • in. interface = your hotspot interface

[Advanced Tab]

[Action Tab]

  • action = mark connection
  • New connection mark = video_stream
  • Passthrough = checked

1st mangle mark connection

We’re going to apply this rule only to IP Address on Src. Address List. This address list was generated automatically every time a user login with mikrotik hotspot (we called trapping user ip into address list).

2nd mangle rule (mark packet)

[General Tab]

  • Chain = prerouting
  • Connection Mark = video_stream

[Action Tab]

  • Action = mark packet
  • New Packet Mark = video_stream_packet
  • Passthrough = checked

2nd mangle packet

This will mark packet from connection marked by previous mangle rule so we can use this marked packet on Queue Tree.

Add Queue Tree

This will limit stream at 384kbps, max Burst at 512kbps for 15 sec and threshold 128kbps.

  • Click on + button to add new rule
  • Name = youtube-stream
  • Parent = global-out
  • Packet Marks = video_stream_packet
  • Max Limit = 384k
  • Burst Limit = 512k
  • Burst Threshold = 128k
  • Burst Time = 15

Queue Tree

Click apply to save the rule and see the result.


You can also set limit to another video stream website such as dailymotion, metacafe and mccont. All we need is to knowing what address used on streaming url. For example dailymotion use cdn.dailymotion.com on streaming address. Next add those address into youtube-stream regex on layer 7 protocol. The complete regexp will be:


Find another streaming address and add them into layer 7 list. Remember, main website url address doesn’t always mean the same address for streaming url. If you put the main website into layer 7 list, you’ll also limiting access speed to the main website.

M Riza

Article by M Riza

Is a blogger since 2007, founder and editor of Oa Ultimate. Working as a network administrator, computer technician, database and web maintainer | Twitter | G+

One Comment → “Mikrotik Hotspot, Limit YouTube based on user profile”

  1. bobbi

    sorry, Greetings, may I learn from your guide above, whatever you have a script to limit browser, download, games, and see the video, you help please, thank you

Leave a Reply


Loading Google+ Comments ...
Loading Facebook Comments ...