Picture of NOC

Traffic Shaping with MikroTik: Ensuring Smooth Network Performance

Traffic shaping helps routers control bandwidth use, reduce latency, and keep critical applications like VoIP and video stable. This guide gives you step-by-step instructions with real MikroTik RouterOS v7 configurations.

Why Traffic Shaping Matters

  • Keep latency low during heavy load.
  • Prioritize voice, video, and interactive apps.
  • Share bandwidth fairly across users and VLANs.
  • Prevent bufferbloat that ruins real-time traffic.

Core Concepts & Terminology

  • Simple Queues: Quick limits per IP/subnet.
  • Queue Tree (HTB): Hierarchical classes for complex policies.
  • PCQ: Per-connection fairness for many hosts.
  • CAKE: Modern shaper with flow isolation, fairness, and DiffServ support.
  • Packet Marking: Classify packets for queue assignment.
  • CIR vs MIR: Guaranteed vs maximum bandwidth.

Packet Flow, FastTrack, and Bridge Notes

  • Simple Queues and Queue Tree usually run in postrouting.
  • FastTrack bypasses queues — exclude or disable it for shaped flows.
  • For bridged traffic, enable use-ip-firewall=yes to make queues see the packets.

How to Set the Correct Shaping Rate

  1. Run a wired speed test during peak hours.
  2. Set shaping at ~95% of actual throughput (both up and down).
  3. On variable links (LTE, DSL), use CAKE autorate or scripts to adapt rates.

Choosing the Right Strategy

  • One WAN, mixed users: Use CAKE in a simple queue.
  • Many users/VLANs: Use PCQ with Queue Tree for fairness.
  • Voice/Video critical: Use DSCP-aware shaping.

1: CAKE Simple Queue Config Example

/queue type
add name=cake-300-50 kind=cake cake-bandwidth=300M cake-diffserv=diffserv4 cake-flowmode=triple-isolate

/queue simple
add name=wan-cake queue=cake-300-50 max-limit=300M/50M target=ether1

2: PCQ + Queue Tree Config Example

/ip firewall mangle
add chain=prerouting in-interface=ether1 action=mark-packet new-packet-mark=download passthrough=no
add chain=postrouting out-interface=ether1 action=mark-packet new-packet-mark=upload passthrough=no

/queue type
add name=pcq-down kind=pcq pcq-classifier=dst-address
add name=pcq-up kind=pcq pcq-classifier=src-address

/queue tree
add name=down parent=global packet-mark=download queue=pcq-down max-limit=200M
add name=up parent=global packet-mark=upload queue=pcq-up max-limit=40M

3: DSCP-Aware Shaping Config Example

/ip firewall mangle
add chain=prerouting in-interface=ether1 dscp=46 action=mark-packet new-packet-mark=voip-down passthrough=no
add chain=postrouting out-interface=ether1 dscp=46 action=mark-packet new-packet-mark=voip-up passthrough=no

/queue type
add name=pcq-voip kind=pcq pcq-classifier=dst-address
add name=pcq-best kind=pcq pcq-classifier=dst-address

/queue tree
add name=down-voip parent=global packet-mark=voip-down queue=pcq-voip limit-at=10M max-limit=30M priority=1
add name=down-best parent=global packet-mark=download queue=pcq-best limit-at=20M max-limit=70M priority=8

FastTrack and QoS

  • FastTrack skips queues.
  • Exclude shaped traffic from FastTrack.
  • Disable FastTrack during testing.

Verification & Monitoring

  • /queue simple print stats – check queue counters.
  • /tool ping 1.1.1.1 interval=0.2 count=50 – measure latency under load.
  • /tool torch interface=ether1 – watch flows.
  • /ip firewall mangle print stats – confirm marks.

Troubleshooting Checklist

  • FastTrack active? Check filter counters.
  • No packet marks? Verify chain/interface.
  • Bridge traffic unseen? Enable the firewall on the bridge.
  • Wrong parent in Queue Tree? Use global for total pipe.
  • Set the bandwidth too high? Lower to ~95% real speed.

Reusable Snippets

Per-IP Simple Queues from Address List

:foreach A in=[/ip firewall address-list find where list="qos-clients"] do={
  :local ip [/ip firewall address-list get $A address]
  /queue simple add name=("sq-" . $ip) target=$ip max-limit=25M/5M queue=cake-25M
}

FAQ

    • Where to set CAKE bandwidth? In the queue type and in the simple queue max-limit.
    • Which diffserv mode? Use 3-class or 4-class, depending on needs.
    • Can I keep FastTrack? Yes, but exclude shaped flows.

Check our list of MikroTik guides.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *