MikroTik PCQ (Per Connection Queues) is designed to evenly distribute bandwidth among users or devices by automatically creating sub-queues for each connection. It is especially useful for optimizing large-scale Quality of Service (QoS) setups.
For deeper look at MikroTik PCQ’s and other MikroTik Queues click here
Steps to Set Up PCQ – IP Based
- Understand Your Network Requirements:
- Identify the traffic you want to manage (e.g., download, upload, specific devices, or users).
- Determine the desired bandwidth limits.
- Set Up Packet Marking (Optional but recommended for detailed control):
- Mark packets using the firewall mangle rules:
/ip firewall mangle add chain=prerouting action=mark-packet in-interface=ether2-LAN new-packet-mark=client_upload /ip firewall mangle add chain=prerouting action=mark-packet in-interface=ether1-WAN new-packet-mark=client_download
- Mark packets using the firewall mangle rules:
- Create PCQ Queue Types:
- Define queue types for upload and download traffic. For example:
/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
- Define queue types for upload and download traffic. For example:
- Apply PCQ to Queues:
- Use queue trees to apply the PCQ configuration:
/queue tree add parent=global queue=PCQ_download packet-mark=client_download /queue tree add parent=global queue=PCQ_upload packet-mark=client_upload
- Alternatively, if using simple queues, directly apply PCQ as follows:
/queue simple add target=192.168.0.0/24 queue=PCQ_upload/PCQ_download
- Use queue trees to apply the PCQ configuration:
Steps to Set Up PCQ – Port Based
Objective: Manage bandwidth equally for different traffic types, such as HTTP (port 80) and HTTPS (port 443).
1. Create PCQ Queue Types
Define PCQ queue types with src-port
and dst-port
classifiers for upload and download traffic:
/queue type add name="PCQ_Upload_Port" kind=pcq pcq-rate=1000000 pcq-classifier=src-port
/queue type add name="PCQ_Download_Port" kind=pcq pcq-rate=1000000 pcq-classifier=dst-port
pcq-rate
: Sets the maximum bandwidth per port (1 Mbps in this example).pcq-classifier
: Usessrc-port
for upload traffic anddst-port
for download traffic.
2. Mark Packets by Ports
Use mangle
rules to mark packets based on the source and destination ports:
/ip firewall mangle add chain=prerouting protocol=tcp dst-port=80,443 action=mark-packet new-packet-mark=web_download
/ip firewall mangle add chain=prerouting protocol=tcp src-port=80,443 action=mark-packet new-packet-mark=web_upload
dst-port=80,443
: Matches HTTP and HTTPS download traffic.src-port=80,443
: Matches HTTP and HTTPS upload traffic.new-packet-mark
: Assigns marks to identify traffic for queues.
3. Create Queue Tree Rules
Apply the PCQ queue types to the marked traffic:
/queue tree add parent=global queue=PCQ_Download_Port packet-mark=web_download
/queue tree add parent=global queue=PCQ_Upload_Port packet-mark=web_upload
parent=global
: Ensures the rules apply to all traffic globally.queue
: Specifies the previously created PCQ queue types.packet-mark
: Links the queue to the marked packets.
Explanation
- This configuration ensures each port (e.g., HTTP or HTTPS) gets equal bandwidth allocation.
- Adjust
pcq-rate
based on your bandwidth limits. - Add more ports or use
udp
if needed for other traffic types.
For further reading, refer to MikroTik PCQ documentation.
Example Scenario: Equal Bandwidth Distribution
You want to limit each user’s download speed to 64 kbps and upload speed to 32 kbps for devices in the 192.168.0.0/24
network.
- Without Mangle Rules:
- Define the queue types:
/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
- Apply a simple queue:
/queue simple add target=192.168.0.0/24 queue=PCQ_upload/PCQ_download
- Define the queue types:
- With Mangle Rules:
- Use the mangle rules to mark packets as shown earlier, and then apply queue trees for more granular control.
For more advanced setups, you can explore features like PCQ burst, IPv6 support, or dynamic adjustments for unknown bandwidth scenarios. You can refer to the detailed documentation on the MikroTik Wiki for additional examples and parameters
Very interesting