Syed Jahanzaib – Personal Blog to Share Knowledge !

January 5, 2012

QOS with Mikrotik [Reference Guide]


QOS With Mikrotik

Following are few scenarios for some examples : I will add more soon.


Post#1 – PCQ base Bandwidth Management with different bandwidth for DAY / NIGHT / DAYS using TIME feature in Mikrotik

Scenario:

We are using Mikrotik CCR1036 ver 6.43.7 , acting as PPPoE NAS, Free-radius (DMA) is providing authentication for users account & also its informing NAS about from which POOL users should get IP address , based on the profile. Example 1mb user gets IP from 1mb pool from NAS.

We require following bandwidth plan:

1 mb user bandwidth plan

  • From 10am till 5pm > 1mb
  • From 5pm till 10am next morning > 2mb
  • Saturday + Sunday Full Time > 2mb
/ip pool
add name=512kb ranges=172.16.114.1-172.16.115.255
add name=2mb ranges=172.16.102.1-172.16.103.255
add name=3mb ranges=172.16.104.1-172.16.105.255
add name=4mb ranges=172.16.106.1-172.16.107.255
add name=6mb ranges=172.16.108.1-172.16.109.255
add name=8mb ranges=172.16.110.1-172.16.111.255
add name=10mb ranges=172.16.112.1-172.16.113.255
add name=1mb ranges=172.16.100.1-172.16.101.255

/queue type
add kind=pcq name=1mb_down pcq-classifier=dst-address pcq-dst-address6-mask=64 pcq-rate=1024k pcq-src-address6-mask=64
add kind=pcq name=2mb_up pcq-classifier=src-address pcq-dst-address6-mask=64 pcq-rate=2048k pcq-src-address6-mask=64
add kind=pcq name=3mb_up pcq-classifier=src-address pcq-dst-address6-mask=64 pcq-rate=3072k pcq-src-address6-mask=64
add kind=pcq name=4mb_up pcq-classifier=src-address pcq-dst-address6-mask=64 pcq-rate=4096k pcq-src-address6-mask=64
add kind=pcq name=6mb_up pcq-classifier=src-address pcq-dst-address6-mask=64 pcq-rate=6144k pcq-src-address6-mask=64
add kind=pcq name=8mb_up pcq-classifier=src-address pcq-dst-address6-mask=64 pcq-rate=8192k pcq-src-address6-mask=64
add kind=pcq name=10mb_up pcq-classifier=src-address pcq-dst-address6-mask=64 pcq-rate=10240k pcq-src-address6-mask=64
add kind=pcq name=512kb_up pcq-classifier=src-address pcq-dst-address6-mask=64 pcq-rate=512k pcq-src-address6-mask=64
add kind=pcq name=2mb_down pcq-classifier=dst-address pcq-dst-address6-mask=64 pcq-rate=2048k pcq-src-address6-mask=64
add kind=pcq name=3mb_down pcq-classifier=dst-address pcq-dst-address6-mask=64 pcq-rate=3072k pcq-src-address6-mask=64
add kind=pcq name=4mb_down pcq-classifier=dst-address pcq-dst-address6-mask=64 pcq-rate=4096k pcq-src-address6-mask=64
add kind=pcq name=6mb_down pcq-classifier=dst-address pcq-dst-address6-mask=64 pcq-rate=6144k pcq-src-address6-mask=64
add kind=pcq name=8mb_down pcq-classifier=dst-address pcq-dst-address6-mask=64 pcq-rate=8192k pcq-src-address6-mask=64
add kind=pcq name=10mb_down pcq-classifier=dst-address pcq-dst-address6-mask=64 pcq-rate=10240k pcq-src-address6-mask=64
add kind=pcq name=512kb_down pcq-classifier=dst-address pcq-dst-address6-mask=64 pcq-rate=512k pcq-src-address6-mask=64
add kind=pcq name=1mb_up pcq-classifier=src-address pcq-dst-address6-mask=64 pcq-rate=1024k pcq-src-address6-mask=64

/queue simple
add max-limit=10M/10M name="Google DNS High Priority 1" priority=1/1 target=8.8.8.8/32
add max-limit=10M/10M name="Google DNS High Priority 2" priority=1/1 target=8.8.4.4/32
add name="1mb pcq day - 10 am till 5 pm" queue=1mb_up/1mb_down target=172.16.100.0/23 time=10h-16h59m59s,mon,tue,wed,thu,fri
add name="1mb pcq & 2mb double up night - 5pm till 10 am" queue=2mb_up/2mb_down target=172.16.100.0/23 time=17h-9h59m59s,mon,tue,wed,thu,fri
add name="1mb pcq & 2mb double up - saturday & sunday - 24 hours" queue=2mb_up/2mb_down target=172.16.100.0/23 time=0s-23h59m59s,sun,sat
add name="2mb pcq day - 10 am till 5 pm" queue=2mb_up/2mb_down target=172.16.102.0/23 time=10h-16h59m59s,mon,tue,wed,thu,fri
add name="2mb pcq & 3mb double up night - 5pm till 10 am " queue=3mb_up/3mb_down target=172.16.102.0/23 time=17h-9h59m59s,mon,tue,wed,thu,fri
add name="2mb pcq double up - saturday & sunday - 24 hours" queue=3mb_up/3mb_down target=172.16.102.0/23 time=0s-23h59m59s,sun,sat
add name="3mb pcq day - 10 am till 5 pm" queue=3mb_up/3mb_down target=172.16.104.0/23 time=10h-16h59m59s,mon,tue,wed,thu,fri
add name="3mb pcq & 6mb double up night -  5pm till 10 am " queue=6mb_up/6mb_down target=172.16.104.0/23 time=17h-9h59m59s,mon,tue,wed,thu,fri
add name="3mb pcq & 6mb double up - saturday & sunday - 24 hours" queue=6mb_up/6mb_down target=172.16.104.0/23 time=0s-23h59m59s,sun,sat
add name="4mb pcq - 24 hours" queue=4mb_up/4mb_down target=172.16.106.0/23 time=0s-1d,sun,mon,tue,wed,thu,fri,sat
add name="6mb pcq - 24 hours" queue=6mb_up/6mb_down target=172.16.108.0/23 time=0s-1d,sun,mon,tue,wed,thu,fri,sat
add name="8mb pcq - 24 hours" queue=8mb_up/8mb_down target=172.16.110.0/23 time=0s-1d,sun,mon,tue,wed,thu,fri,sat
add name="10mb pcq - 24 hours" queue=10mb_up/10mb_down target=172.16.112.0/23 time=0s-1d,sun,mon,tue,wed,thu,fri,sat
add name="512kb pcq day - 10 am till 5 pm" queue=512kb_up/512kb_down target=172.16.114.0/23 time=10h-16h59m59s,mon,tue,wed,thu,fri
add name="512kb pcq & 1mb double up night - 5 pm till10 am" queue=1mb_up/1mb_down target=172.16.114.0/23 time=17h-9h59m59s,mon,tue,wed,thu,fri
add name="512kb pcq & 1mb double up - saturday & sunday - 24 hours" queue=1mb_up/1mb_down target=172.16.114.0/23 time=0s-23h59m59s,sun,sat
add name="512kb for UKNOWN users IF any by zaib  - 24 hours" queue=512kb_up/512kb_down target=172.16.0.0/16 time=0s-23h59m59s,sun,mon,tue,wed,thu,fri,sat

in User PPP Profile, I have added following line

/queue simple remove [find dynamic]

This line will remove any Dynamic Queue that will be created by DMA.

Done.

Screenshots …

PCQ base simple Queues with TIME settings, each queue will be enabled as per time

q1

 

q2

q3

 

q4


Remove DYNAMIC Queue by Script command

Its useful when you are using PCQ base queueus , and your raidus still sends dynamic queues, you can add this in pppoe profile startups script section, so any dynamic queue will be removed whenever any user logins

/queue simple remove [find dynamic]

Post#2 – Limit user traffic using PCQ (also useful for Hotspot Bypassed MAC address)

To limit all users 192.168.1.0/24 to 512kb epr user, using PCQ, use following script.

/queue type
add kind=pcq name=download-512kb pcq-burst-rate=0 pcq-burst-threshold=0 pcq-burst-time=10s pcq-classifier=dst-address pcq-dst-address-mask=32 pcq-dst-address6-mask=64 pcq-limit=50 pcq-rate=524288 \
pcq-src-address-mask=32 pcq-src-address6-mask=64 pcq-total-limit=2000

add kind=pcq name=upload-512kb pcq-burst-rate=0 pcq-burst-threshold=0 pcq-burst-time=10s pcq-classifier=src-address pcq-dst-address-mask=32 pcq-dst-address6-mask=64 pcq-limit=50 pcq-rate=524288 \
pcq-src-address-mask=32 pcq-src-address6-mask=64 pcq-total-limit=2000

/queue simple
add burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s comment="Limit every Users at 512kb using PCQ. Can be used for hotspot BYPASSED macs too. Can be used for multi purpose  Syed Jahanzaib" \
direction=both disabled=no interface=all limit-at=0/0 max-limit=0/0 name=512k-limit packet-marks="" parent=none priority=8 queue=upload-512kb/download-512kb target-addresses=192.168.1.0/24 \
total-queue=default-small

Change the Bandwidth and Target IP addresses to meet your local requirements.
Bandwidth example:
512k = 524288
1mb = 1048576
2mb = 2097152
4mb = 4194304

Result as showed in the image below . . .

queue-pcq-per-user

Post#3 – Allowing specific extension Low Priority over other traffic

In this example we are marking traffic via mangle rules. .iso extension is marked as low priority traffic , and all other traffic is marked as hi priority traffic.

For example We have 256kb internet bandwidth in total. and we want that when users are downloading any .iso file, it gets low priority over other traffic i.e browsing etc. Use the following.

/ip firewall mangle
add action=mark-connection chain=postrouting comment="Mark Conn for .iso Ext" content=iso disabled=no new-connection-mark=iso-conn passthrough=yes
add action=mark-packet chain=postrouting comment="Mark Pkts for iso-conn Ext" connection-mark=iso-conn disabled=no new-packet-mark=lo-prio-traffic-pkts passthrough=no
add action=mark-connection chain=postrouting comment="Mark Conn for all other traffic" content=!iso disabled=no new-connection-mark=hi-prio-traffic-conn passthrough=yes
add action=mark-packet chain=postrouting comment="Mark Pkts for all other traffic" connection-mark=hi-prio-traffic-conn disabled=no new-packet-mark=hi-prio-traffic-pkts passthrough=no
/queue simple add name=wan_conn_limit interface=ether1 max-limit=256k/256k
/queue simple add name=hi-prio-traffic interface=ether1 parent=wan_conn_limit packet-marks=hi-prio-traffic-pkts priority=1
/queue simple add name=lo-prio-traffic packet-marks=lo-prio-traffic-pkts interface=ether1 parent=wan_conn_limit priority=8

4# Allowing Specific File Extensions High / Limited / Unlimited Bandwidth

For example, You have a network and every user have there bandwidth limited at 256kb. Now you want that if a user is downloading .FLV video file , He can view/download it at unlimited speed regardless of his allowed speed limit, i.e 256kb package, Use the following.

First mark all packets with .flv extention.

/ip firewall mangle
add action=mark-connection chain=postrouting comment="Mark Conn for .flv Ext" content=flv disabled=no new-connection-mark=flv-conn passthrough=yes

add action=mark-packet chain=postrouting comment="Mark Pkts for flv-conn Ext" connection-mark=flv-conn disabled=no new-packet-mark=flv passthrough=no

Now Create a Queue Tree and Set Unlimited or Limited Bandwidth (OR As per your requirements if you want to allot specific amount, set it) to Marked Packets

/queue tree
add burst-limit=0 burst-threshold=0 burst-time=0s disabled=no limit-at=100M max-limit=100M name=Unlimited-Speed-4-Marked-Pkts packet-mark=flv parent=global-out priority=1 queue=defaul

You can use the same in reverse to limit specific extension type bandwidth usage.

5# Allowing Specific Ports High Priority over other traffic

First we need to mark protocols. (In this example we are using SMTP port 25 )

/ip firewall mangle add chain=prerouting protocol=tcp port=25 connection-state=new action=mark-connection new-connection-mark=hi_prio_conn
/ip firewall mangle add chain=prerouting connection-mark=hi_prio_conn action=mark-packet new-packet-mark=hi_prio_conn_pkts

Now we will create Simple Queue and give high priority to marked packets and other packets low priority. (In this example we have 2Mb WAN connection)

/queue simple add name=wan_conn_limit interface=ether1 max-limit=2M/2M
/queue simple add name=prio interface=ether1 parent=wan_conn_limit packet-marks=hi_prio_conn_pkts priority=1
/queue simple add name=other interface=ether1 parent=Internet priority=8

Now SMTP traffic will get higher priority over other traffic.

6# Equal Distribution of Bandwidth for a number of users using PCQ

If you have a 512 kbps WAN connection and you want to share this equally among your users  but if only one pc is active it should have the full 512 kbps, if 2 pcs are active 256 kbps each and vise versa.
As shown in the image below . . .


Use the following:

/queue type add name="PCQ_download" kind=pcq pcq-rate=512k pcq-classifier=dst-address
/queue type add name="PCQ_upload" kind=pcq pcq-rate=512k pcq-classifier=src-address

/queue simple add queue=PCQ_upload/PCQ_download target-addresses=192.168.2.0/24

7# Limiting Single User Bandwidth via Simple QUEUE (Lookout for order number)

/queue simple add name="Limiting Zaib to 256kb" target-addresses=192.168.2.6 max-limit=256k/256k

8# Simple Queue with BURST

Following simple queue with BURST

– Limit user at 64kb in general.
– When the user will download at full 64kbps speed, he will be able to burst upto 256kb for 5 seconds. after 5 seconds , user will fall to 64kb again for next 5 seconds.

In short 5 seconds on load 256kbps, and next 5 seconds, 64kbp.

/queue simple
add burst-limit=256k/256k burst-threshold=128k/128k burst-time=20s/20s direction=both disabled=no interface=all limit-at=0/0 max-limit=64k/64k name=queue1 \
packet-marks="" parent=none priority=8 queue=default-small/default-small target-addresses=172.16.0.10/32 total-queue=default-small

9# Give specific web site assigned Bandwidth on per user basis [updated: 14th April, 2014]

For example you want to limit bandwidth on per user basis for SPECIFIC WEBSITE ONLY. Let’s say 4mb per user for facebook.com
The logic is simple.
1- First create a script that adds the web site ip to an address list.
2- Add scheduler that runs above script after every 5 minutes so that even if the web site ip gets changes, it will update accordingly.
3- Now mark connection and packets for above created address list.
4- Add PCQ queue type (Bandwidth that will be distributed on per user basis using single simple queue)
5- Finally add a simple queue that will distribute bandwidth for marked packets using PCQ for per user basis.


/system script
add name=facebook-list policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api source="# Script to add Facebook DNS IP addressess \r\
\n# Syed Jahanzaib / aacable@hotmail.com\r\
\n:log warning \"Script Started ... Adding Facebook DNS ip's to address list name   facebook_dns_ips\"\r\
\n:foreach i in=[/ip dns cache find] do={\r\
\n:local bNew \"true\";\r\
\n:local cacheName [/ip dns cache all get \$i name] ;\r\
\n:if ([:find \$cacheName \"facebook\"] != 0) do={\r\
\n:local tmpAddress [/ip dns cache get \$i address] ;\r\
\n:put \$tmpAddress;\r\
\n:if ( [/ip firewall address-list find ] = \"\") do={\r\
\n:log info (\"added entry: \$[/ip dns cache get \$i name] IP \$tmpAddress\");\r\
\n/ip firewall address-list add address=\$tmpAddress list=facebook_dns_ips comment=\$cacheName;\r\
\n} else={\r\
\n:foreach j in=[/ip firewall address-list find ] do={\r\
\n:if ( [/ip firewall address-list get \$j address] = \$tmpAddress ) do={\r\
\n:set bNew \"false\";\r\
\n}\r\
\n}\r\
\n:if ( \$bNew = \"true\" ) do={\r\
\n:log info (\"added entry: \$[/ip dns cache get \$i name] IP \$tmpAddress\");\r\
\n/ip firewall address-list add address=\$tmpAddress list=facebook_dns_ips comment=\$cacheName;\r\
\n}\r\
\n}\r\
\n}\r\
\n}\r\
\n# Script Ended..."

/system scheduler
add comment="Add Facebook IP's to address list name facebook-list after every 5 minutes / zaib" disabled=no interval=5m name=add_fb_to_list_scheduler_every_5mnts on-event=facebook-list policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-date=feb/11/2014 start-time=00:00:00

/ip firewall mangle
add action=mark-connection chain=postrouting comment="Mark Conn for FB Site / zaib" disabled=no dst-address-list=facebook_dns_ips new-connection-mark=FB-conn passthrough=yes
add action=mark-packet chain=postrouting comment="Mark Packtes for FB-CONN / zaib" connection-mark=FB-conn disabled=no new-packet-mark=FB_Packets passthrough=no

/queue type
add kind=pcq name=Download-4mb pcq-burst-rate=0 pcq-burst-threshold=0 pcq-burst-time=10s pcq-classifier=dst-address pcq-dst-address-mask=32 pcq-dst-address6-mask=64 pcq-limit=50 pcq-rate=4194304 \
pcq-src-address-mask=32 pcq-src-address6-mask=64 pcq-total-limit=2000
add kind=pcq name=Upload-4mb pcq-burst-rate=0 pcq-burst-threshold=0 pcq-burst-time=10s pcq-classifier=src-address pcq-dst-address-mask=32 pcq-dst-address6-mask=64 pcq-limit=50 pcq-rate=4194304 \
pcq-src-address-mask=32 pcq-src-address6-mask=64 pcq-total-limit=2000

/queue simple
add burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s comment="Limit FB speed 4mb per user using PCQ  / Syed Jahanzaib" direction=both disabled=no interface=all limit-at=0/0 max-limit=0/0 name=\
4mb_Limit_For_FB_Per_User packet-marks=FB_Packets parent=none priority=8 queue=Upload-4mb/Download-4mb target-addresses="" total-queue=default-small

 

Do remember, its just an example to show you how you can twist things, You can modify it as per your requirements 🙂


Some Notes:

The target-address is used to specify the host that you want to shape… target-address is the address of (for example) your client who’s speed you are about to limit.

Destination-address is for more advanced shaping… for example to shape someone’s access to a specific server dst-address is the server to which this client will connect (if you like to limit his speed only when he connects to this one specific server)


Syed Jahanzaib

70 Comments »

  1. NIce sharing!
    jahanzaib bhai if user packge is 512kb and i want to limit its streaming speed e.g flv , avi etc… to 256kb then what shoud be the settings in qos or in proxy server like squid?

    Like

    Comment by faizan — January 5, 2012 @ 4:18 PM

    • Just create simple queues for your users.
      Above the queue, create one more queue which will limit the .flv or any marked packets.

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — January 6, 2012 @ 10:54 AM

      • Jahanzaib Bhai its not working with ros 6.0 version of mikrotik.
        /queue
        abled=no limit-at=100M
        rk=flv parent=global-ou
        input does not match a
        this error comes in terminal

        global out is not found…

        Like

        Comment by waqas hussain — July 24, 2013 @ 3:09 AM

  2. Hello syed,
    Really nice sharing.
    I have one query. If want to make make users to have unlimited speed on accessing web pages and mails or just browsing any site. But users will get limited speed or lower priority if they are downloading anything. Means accessing websites with highest priority and download with lower priority.
    Please help me for this.

    Like

    Comment by Ravi — January 6, 2012 @ 9:20 AM

    • And syed I have added Equal distribution of bandwidth by PCQ. But I want to know that where can I see the changes in access distribution and user’s usage limit etc after adding this PCQ?

      Like

      Comment by Ravi — January 6, 2012 @ 9:43 AM

    • I have updated the article. Check it again.

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — January 6, 2012 @ 11:08 AM

    • how it is possible brother ?

      Like

      Comment by Ijaz AHmed — April 26, 2012 @ 11:46 PM

      • Where is the article… please send the URL… Regards

        Like

        Comment by Ijaz Ahmed — April 27, 2012 @ 3:10 PM

  3. dear i am confuse a in interface= ether1(the either 1 is LAN or WAN/DSL) in the Allowing specific extension Low Priority over other traffic topic.

    Like

    Comment by Suleman — January 7, 2012 @ 3:05 AM

  4. salam dear bro.

    for example .flv ki extension files full lan speed 100m yea chalen limited speed 50m per download hoon gi.
    ager ma chaon k ,flv unlimited per download hoon but youtube ki choti files like below 100MB files.
    coz youtube and many other sites also have 700MB+ big files in . flv files.

    kindly also explain how to limit to file size please. this is realy big issue in this sanerio. 🙂

    Like

    Comment by netbizpk — January 9, 2012 @ 12:23 AM

  5. Assalaam o Alekom .

    sir……….kindly understand me..this script.
    /queue simple add name=wan_conn_limit interface=ether1 max-limit=2M/2M

    (interface=ether1) means (interfac=Local)

    JAZAKALLAH

    Like

    Comment by waqar hussain — January 9, 2012 @ 9:15 AM

  6. Asalaam o Alekom..
    sir….kya ye sab ek saath configure karney hain…..? OR ye PCC-LB key saath work kartein hain ya
    nahi…..? plz rpl

    1# Allowing specific extension Low Priority over other traffic
    1# Allowing Specific File Extensions High / Limited / Unlimited Bandwidth
    2# Allowing Specific Ports High Priority over other traffic
    3# Equal Distribution of Bandwidth for a number of users using PCQ
    4# Limiting Single User Bandwidth via Simple QUEUE (Lookout for order number)

    JAZAKALLAH….!

    Like

    Comment by waqar hussain — January 9, 2012 @ 9:48 PM

    • # These are topic wise short reference guide. Don’t just blindly copy paste them, They are just examples.

      # Yes You can make them work with PCC, although it is complex to make them work together.

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — January 10, 2012 @ 12:41 PM

  7. syed if I want to give lower priority to some more extensions like .flv, .mp3 etc, then do I need to write the first code (1# Allowing specific extension Low Priority over other traffic) separately for each extension? or only few lines will be added rather than all for all types of extensions?

    Like

    Comment by Ravi — January 11, 2012 @ 9:25 AM

  8. How to Maximise Download Speed via Outbound Traffic Shaping?Its there any possible way to have. Full 2mb download 175kb Upload. When I surf the web use all bandwidth and parallel when bittorent is downliading to not slow down the web surfinc experience? There is some tweaks on prioritizing ACK, SYN, if you know please help. Your tutorials. are excellent. Thank you for the time.

    Like

    Comment by Alex — January 11, 2012 @ 9:43 AM

  9. Hi Syed,
    I have got one error. Its when I tried to use the rule #2 for making port 25 on high priority.
    In queue the “parent = internet” its not defined anywhere and thus it is not coming in the parent field and gives me error.
    Please check the rule and let me know how to make it correct?

    Like

    Comment by Ravi — February 6, 2012 @ 10:13 AM

  10. About your “Equal Distribution of Bandwidth for a number of users using PCQ” – I think it’s wrong example, you must use pcq-rate=0 and set max-limit for queue, because pcq-rate is maximal available data rate of each sub-steam or am I wrong?

    Like

    Comment by Alexander — February 13, 2012 @ 2:52 PM

    • Alexander, can you mention the rule overhere, what ever you think should be in PCQ?

      Like

      Comment by Ravi — February 14, 2012 @ 7:20 AM

      • believe me, I’ve been studying routerOS by myself is not the first year and still not 100% sure how to properly organize a Equal Distribution of Bandwidth with using the pcq, but if you’re carefully look at this picture http://wiki.mikrotik.com/wiki/File:PCQ3.png and this http://wiki.mikrotik.com/wiki/File:PCQ3.png you understand what I mean, pay attention to the parameter pcq-rate and the max-limit

        Like

        Comment by Alexander — February 14, 2012 @ 9:23 AM

      • Queue Tree for “Equal Distribution of Bandwidth for a number of users using PCQ”

        /queue tree
        add burst-limit=0 burst-threshold=0 burst-time=0s disabled=no limit-at=0 \
        max-limit=19M name=queue1 parent=global-out priority=8
        add burst-limit=0 burst-threshold=0 burst-time=0s disabled=no limit-at=0 \
        max-limit=19M name=queue2 parent=global-total priority=8
        add burst-limit=0 burst-threshold=0 burst-time=0s disabled=no limit-at=0 \
        max-limit=3891k name=queue3 parent=global-out priority=8
        add burst-limit=0 burst-threshold=0 burst-time=0s disabled=no limit-at=0 \
        max-limit=699k name=queue4 parent=global-total priority=8
        add burst-limit=0 burst-threshold=0 burst-time=0s disabled=no limit-at=0 \
        max-limit=0 name=1_ISP1_DOWNLOAD packet-mark=internetdownload parent=\
        queue1 priority=8 queue=PCQ_ISP1_DL
        add burst-limit=0 burst-threshold=0 burst-time=0s disabled=no limit-at=0 \
        max-limit=0 name=2_ISP1_UPLOAD packet-mark=internetupload parent=queue2 \
        priority=8 queue=PCQ_ISP1_UPL
        add burst-limit=0 burst-threshold=0 burst-time=0s disabled=no limit-at=0 \
        max-limit=0 name=3_ISP2_DOWNLOAD packet-mark=internetdownload_1 \
        parent=queue3 priority=8 queue=PCQ_ISP2_DL
        add burst-limit=0 burst-threshold=0 burst-time=0s disabled=no limit-at=0 \
        max-limit=0 name=4_ISP2_UPLOAD packet-mark=internetupload_1 parent=\
        queue4 priority=8 queue=PCQ_ISP2_UPL

        pcq-queue types

        /queue type
        add kind=pcq name=PCQ_ISP1_DL pcq-burst-rate=0 pcq-burst-threshold=0 \
        pcq-burst-time=10s pcq-classifier=dst-address pcq-dst-address-mask=32 \
        pcq-dst-address6-mask=128 pcq-limit=256 pcq-rate=17999k \
        pcq-src-address-mask=32 pcq-src-address6-mask=128 pcq-total-limit=10240
        add kind=pcq name=PCQ_ISP1_UPL pcq-burst-rate=0 pcq-burst-threshold=0 \
        pcq-burst-time=10s pcq-classifier=src-address pcq-dst-address-mask=32 \
        pcq-dst-address6-mask=128 pcq-limit=256 pcq-rate=17999k \
        pcq-src-address-mask=32 pcq-src-address6-mask=128 pcq-total-limit=10240
        add kind=pcq name=PCQ_ISP2_DL pcq-burst-rate=0 pcq-burst-threshold=0 \
        pcq-burst-time=10s pcq-classifier=dst-address pcq-dst-address-mask=32 \
        pcq-dst-address6-mask=128 pcq-limit=256 pcq-rate=3686k \
        pcq-src-address-mask=32 pcq-src-address6-mask=128 pcq-total-limit=10240
        add kind=pcq name=PCQ_ISP2_UPL pcq-burst-rate=0 pcq-burst-threshold=0 \
        pcq-burst-time=10s pcq-classifier=src-address pcq-dst-address-mask=32 \
        pcq-dst-address6-mask=128 pcq-limit=256 pcq-rate=662k \
        pcq-src-address-mask=32 pcq-src-address6-mask=128 pcq-total-limit=10240

        Like

        Comment by Alexander — February 14, 2012 @ 11:31 AM

  11. sorry, make mistake about picture, compare http://wiki.mikrotik.com/wiki/File:PCQ3.png http://wiki.mikrotik.com/wiki/File:PCQ4.png

    Like

    Comment by Alexander — February 14, 2012 @ 9:25 AM

    • Alexander: is it only limited to 7 users only.
      In my connection i have got 1mbps connection at WAN and now I want to distribute it to approximately 20 users.
      So what do u suggest? will this be good idea to do such distribution?

      Like

      Comment by Ravi — April 30, 2012 @ 7:39 AM

  12. Hi Sir,
    I am distributing equal bandwidth for number of users in a cafe through simple PCQ. I don’t want to limit speed for admin computer. How can this be possible?

    I am also doing 3 WAN PCC load balancing so I want to connect main PC after load balance with unlimited speed.

    Thanks

    Like

    Comment by Nouman — February 21, 2012 @ 1:43 PM

  13. Hello Sir,
    Really nice sharing.
    I have one query. If want to make make users to have unlimited speed on accessing web pages and mails or just browsing any site. But users will get limited speed or lower priority if they are downloading anything. Means accessing websites with highest priority and download with lower priority.
    Please help me for this.

    I cant any post regarding this…

    Best regards
    Ijaz Ahmed

    Like

    Comment by Ijaz Ahmed — April 30, 2012 @ 2:14 PM

    • Well you can achieve this in many ways.
      One way is to mark traffic for download extensions like .exe .mp3 .flv etc and then using queue for these marked packets, you can control speed for downloading.
      You have to first understand the basis on how queue and packet marking works in Mikrotik world. Read first.

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — May 1, 2012 @ 10:34 AM

  14. how i can give users browsing speed diferant than download speed
    thank you

    Like

    Comment by hesham — May 22, 2012 @ 11:08 AM

    • There is no difference in browsing and downloading, bith work on HTTP port 80.
      you can use Packet marking for specif extensions like .exe .mp3 .zip and give priority by making anopther queue above normal queues, There are various ways to do it. Search.

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — May 22, 2012 @ 1:24 PM

  15. web browser did not send challenge response (try again, enable JavaScript)
    sir ya problum kun aata he or is ke lye setting kya karne hoge

    Like

    Comment by sheeraz — June 8, 2012 @ 6:54 AM

  16. ip address print

    Flags: x – disable, I – invalid, D – dynamic
    # ADDRESS NETWORK INTERFACE
    0 ;;; default configuration
    192.168.88.1/24 192.168.88.0 ether2-local
    1 192.168.2.1/24 192.168.2.0 ether2-local
    2D 192.168.1.2/24 192.168.1.0 ether1-public

    My ip route configuration
    Flags: x – disable, A – active, D – Dynamic,
    C – conect, s – static , r – rip, b – bgp, o – ospf, m – mme,
    B – blackhole, u – unreachable, p prohibit
    # DST-ADDRESS PREFF-SCR GATEWAY DISTANCE
    0 ADS 0.0.0.0/0 192.168.1.1 1————————-> here is my modem ip
    1 ADC 192.168.1.0/24 192.168.1.2 ether1-public 0————————> here is my ip client will beable access internet
    2 ADC 192.168.2.0/24 192.168.2.1 ether2-local 0————————> here is my ip range for client
    3 ADC 192.168.88.0/24 192.168.88.1 ether2-local 0————————> here is my ip routerboard / mikrotik

    Total connection 2 Mbps and will be share to 20 pc

    my question – how to manage my bandwich 2 Mbps for 20 pc
    – what to do to restricted user from use; IDM or anything dowload manager software
    Sorry I m really newbe on mikrotik and i dont like use simple queue
    For your information and sugest thank you very much

    Regards

    Ali

    Like

    Comment by Ali Muhamad — June 18, 2012 @ 8:20 PM

  17. Sir,
    above techniques are really awesome, but when i using the Dmasoftlab Radius, which create queues when we create plan i radius.
    is it possible to above the qos techniques along with radius server , is it is really possible….

    Like

    Comment by tamilmaran — June 21, 2012 @ 2:08 PM

  18. Dear Sir
    I am using PPPOE and giving net to clients and now when i give 128kbps down and when client download any file and at the same time if he try to browse any site its getting very slow because all 128kbps is going in download of that file any possibility to share the bandwidth 128kbps equally between all the application used. I am also using ISA Server as gateway its dividing bandwidth by number of application. like this all the application gets equal bandwidth. please email me regarding this issue hussainsorangi@hotmail.com

    Like

    Comment by Hussain — August 13, 2012 @ 4:33 AM

  19. i cant see the mangle in this line 3# Equal Distribution of Bandwidth for a number of users using PCQ
    for trafick marking. CMIIW

    Like

    Comment by setting mikrotik — September 22, 2012 @ 8:02 AM

  20. sir kia ye rule har user par alag alag mac address main lag sakhta hai kia….ip main tu kam karta hai m chata hn kay mac address main kam kary?

    Like

    Comment by Asif Rehman — October 10, 2012 @ 12:24 AM

  21. pls update the article priotause different type og traffic like http,videoand torrent

    pls sir

    Like

    Comment by mirza baig — December 3, 2012 @ 2:02 AM

  22. sorry 4 d typing mistake in previous post

    pls update the article prioratize d different type of traffic like http,video and torrent

    pls sir

    Like

    Comment by mirza baig — December 3, 2012 @ 2:04 AM

  23. Sir, can you give me a best advice to applicate QoS in Hotspot Mikrotik ?
    Thanks before

    Like

    Comment by victorthe — February 15, 2013 @ 2:14 PM

  24. syed sir, can you give some tip for my doupts i have 12 mbps
    and ineed some model of mikrotik qos in first step first priority for icmp,dns and second for voip ,third for http,https fourth for remote fifth for video six for ftp and snmp port
    seven for torrent

    and mainly if some my clients when ever go to check speedtest like speedtest.net it must be first priority. how to set this

    Like

    Comment by siva — March 31, 2013 @ 6:49 PM

  25. Sir, how can we check numbers of users are using a simple queue based on pcq queue types.Let say if i have 172.16.0.0/16 as a target address in queue.

    Like

    Comment by Nadir — June 21, 2013 @ 9:37 AM

  26. can we generate graph or report of each user bandwidth usage.

    Like

    Comment by Nadir — June 21, 2013 @ 9:41 AM

    • yes you can, it can be done via mikrotik base graphs too, but they vanish after reboot, using any linux base mrtg , you can store users graphs by using snmp to the user queue.

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — June 23, 2013 @ 10:55 AM

      • Sir, Please explain a bit more.

        Like

        Comment by Nadir — June 23, 2013 @ 12:30 PM

  27. Dear sir, the above pcq example looks slightly misleading there are two different parameters pcq rate and pcq max limit. The pcq image example is pcq max limit while your configuring is pcq rate example.Please explain the difference between them.

    Like

    Comment by Nadir — June 21, 2013 @ 12:32 PM

  28. its not working with the ros 6.0

    Like

    Comment by waqas hussain — August 7, 2013 @ 5:42 AM

  29. Dear i want to count number of users using internet in queues as i have 500 to 1000 user so just want to figure out that my pcq queue are working fine surely it can’t be don using torch. Or any pcq statistics value witch can show me number of users using internet currently.

    Like

    Comment by Nadir — October 5, 2013 @ 9:07 PM

    • AFAIK, Its not possible to watch each user queue using PCQ.

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — October 6, 2013 @ 10:09 AM

      • any other method to monitor pcq is distributing bandwidth fairly and secondly do we need to change pcq total limit or pcq limit parameter for large numbers of user (500 to 1500) or default value are ok.

        Like

        Comment by nadir — October 9, 2013 @ 11:08 PM

  30. Assalamun Alayk…

    Janab,

    i am configure pcg in my server for all user same speed, with mangle rule, queue type,and queue tree. so all user same speed internet
    but can i one ip address unlimited speed proved.

    /ip firewall mangle add chain=prerouting action=mark-packet \
    in-interface=ether1-LAN new-packet-mark=client_upload
    /ip firewall mangle add chain=prerouting action=mark-packet \
    in-interface=ether2-WAN new-packet-mark=client_download

    /queue type add name=”PCQ_download” kind=pcq pcq-rate=64000 pcq-classifier=dst-address
    /queue type add name=”PCQ_upload” kind=pcq pcq-rate=32000 pcq-classifier=src-address

    /queue tree add parent=global-in queue=PCQ_download packet-mark=client_download
    /queue tree add parent=global-out queue=PCQ_upload packet-mark=client_upload

    Like

    Comment by Sirajali — October 23, 2014 @ 12:53 PM

  31. Sir………How to bypass simple queue limit of users in mikrotik
    For 1 website i mean “facebook.com”
    ALLAH aap ko Jaza e Khair dey………..!

    Like

    Comment by Salman — April 24, 2015 @ 4:54 AM

  32. Sir………How to bypass simple queue limit of users in mikrotik
    For 1 website i mean “facebook.com”
    ALLAH aap ko Jaza e Khair dey…….!

    Like

    Comment by Salman — April 26, 2015 @ 6:27 AM

  33. Sir………this article/script for user basis and hotspot users……..!
    Give specific web site assigned Bandwidth on per user basis [updated: 14th April, 2014]
    But ………..Sir we want to specific website assigned bandwidth unlimited on all users
    and Scenario…….PCC-LB>>>SQUID>>>>Mikrotik manual IP/MAC/Simple Queue
    hope u understand……..!
    ALLAH aap ko Jaza e Khair Dey………………

    Like

    Comment by Salman — April 28, 2015 @ 6:48 AM

  34. Sir………this article/script for user basis and hotspot users……..!
    Give specific web site assigned Bandwidth on per user basis [updated: 14th April, 2014]
    But ………..Sir we want to specific website assigned bandwidth unlimited on all users
    and Scenario…….PCC-LB>>>SQUID>>>>Mikrotik manual IP/MAC/Simple Queue>>>>Users
    hope u understand……..!
    Sir………..how to edit this article on my scenario..
    ALLAH aap ko Jaza e Khair Dey………………

    Like

    Comment by Salman — April 30, 2015 @ 3:49 AM

  35. can we assign bandwidth limit on mac address ?

    Like

    Comment by ANEEB TALPUR — May 3, 2015 @ 11:52 PM

  36. How to Bypass user by MAC, from IP Bindings and countrol them speed. Hi
    Dear All
    I want to let user access the network without login info.
    But in the same time i want to control them speed.
    Any help please.

    Thank you.

    Like

    Comment by Ahmed — December 11, 2015 @ 8:33 PM

  37. Hi,

    I have been using hotspot and userman for a couple of years, I would like to know how I can set shared users to share bandwidth.

    When 2 users are logged on the hotspot with the same username, they each get the bandwidth specified in user-manager.

    How can this be changes so that if 2 users are logged in the bandwidth will be 50% to A and 50% to B

    Like

    Comment by Naveed Arif — July 6, 2016 @ 7:34 PM

    • not possible with already provided options. you have to create pool+queues and assign user that pool (that pool will be limited by static queues made custom.

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — July 7, 2016 @ 8:16 PM

  38. sir i wanted to give .ipsw extension full download speed or a website itself but tried the code but didn’t work i am using CCR1036 with os version 6.37 tried the code listed
    # Allowing Specific File Extensions High / Limited / Unlimited Bandwidth
    can you please help me with it

    Like

    Comment by koichimalla — September 30, 2016 @ 5:44 PM

  39. Dear Zaib
    Please guide me … i want to give priority to facebook… when i do with pcq… My pppoe user get extra speed from their package ..lets say … if I create a queue type pcq with priority by marking facebook packets and limit at 1MB… PPPOE users of 1 mb starts receiving 1MB+Facebook bandwidth. how it will be possible in their package but prioritizing facebook

    Like

    Comment by eezzi com — October 22, 2016 @ 12:14 PM

  40. Hello,
    I have more than 10 Vlans, each running its own hotspot . How do i deploy PCQ configs inorder for each user to equally enjoy same bandwidth in each hotspot vlan without affect out users. Example will help

    Like

    Comment by Michael — November 28, 2016 @ 9:57 PM

  41. ASSALAAM O ALEKOM…..Sir i have usiing “Limit user traffic using PCQ” without hotspot so i want to use
    this methord
    “Lets manipulate ! Part-1 / Traffic base priority via Queue Tree in Mikrotik” with “Limit user traffic using PCQ”
    how can use it………………

    Like

    Comment by Salman Qureshi — December 13, 2016 @ 3:03 AM

  42. Zaib,
    I am prepareing hotspot setup for my warung kopi (coffee shop) with adsl line.
    i have 2 rbs; rb750 and hAP ac lite.

    i am planning to connect hAP with ether to RB750.
    I have no idea where to put bw management rules on RB750 or hAP?
    and where do i set up hotspot server? rb750 or hAP?

    if i put rb750 as hotspot server, then hAP will be hotspot client, correct?

    what i do know is hAP will be my AP.

    Thanks for this guide, appreciate your advise to my network

    Like

    Comment by machfud — September 23, 2017 @ 1:16 PM

    • you can use HAP as access point, and connect one cable with rb750, this way hap will be only AP. then you can do rest of config at 750, HAP is very light model, so go with rb750

      Like

      Comment by Syed Jahanzaib / Pinochio~:) — October 10, 2017 @ 8:31 AM


RSS feed for comments on this post. TrackBack URI

Leave a comment