tagMangle

circle-info

Mangle rules allow RouterOS to mark packets and connections for Quality of Service (QoS), policy-based routing, bandwidth management, and advanced traffic manipulation without modifying the actual packet data.

In WinBox you can configure mangle in IP -> Firewall -> Mangle, or you can use terminal with command /ip firewall mangle

Mangle is processed before NAT and routing decisions, making it essential for traffic shaping, load balancing, and policy routing.


Mangle fundamentals

How mangle works

Marking types:

  • Packet marks - Mark individual packets for QoS and routing

  • Connection marks - Mark entire connections for bandwidth management

  • Routing marks - Direct packets through specific routes

  • DSCP marks - Set Differentiated Services Code Point for QoS

Mangle chains:

  • prerouting - Before routing decision (all incoming packets)

  • input - Packets destined for router (before input filter)

  • forward - Packets being routed through (before forward filter)

  • output - Packets from router (before output filter)

  • postrouting - After routing decision (all outgoing packets)

Processing order


Basic packet marking

Mark packets by protocol

Basic packet marking for common protocols:

Mark by source/destination

Mark traffic based on network addresses:


Connection marking

Mark connections for bandwidth management

Connection marking allows tracking entire sessions:

Per-user connection marking

Mark connections per user or device:


QoS implementation with mangle

DSCP marking for QoS

Set DSCP values for enterprise QoS:

Priority marking with TOS

Set Type of Service bits for priority:


Policy-based routing with mangle

Route marking for multiple WANs

Direct traffic through specific gateways:

Load balancing with PCC

Per Connection Classifier for load balancing:

Policy routing by application

Route specific applications through different paths:


Advanced mangle techniques

Gaming traffic optimization

Optimize gaming traffic with low latency marking:

Time-based traffic marking

Different marking based on time of day:

Bandwidth monitoring with mangle

Mark traffic for monitoring and accounting:


Mangle with Queue Tree

Prepare traffic for queue tree

Mangle marks are essential for queue tree bandwidth management:

Gaming and VoIP priority queuing


Monitoring and troubleshooting mangle

Monitor mangle rules

Debug mangle issues

Performance monitoring


Layer-7 protocol detection

Mark traffic by detected protocols

Use layer-7 patterns for application detection:


chevron-rightShow complete QoS mangle setuphashtag

Mangle best practices

Performance optimization

  1. Order rules efficiently - Most frequent matches first

  2. Use passthrough wisely - Set to 'no' for final marking

  3. Minimize regex patterns - Layer-7 detection impacts performance

  4. Use connection marking - More efficient than per-packet marking

  5. Combine conditions - Reduce rule count with multiple criteria

Design recommendations

  1. Plan marking strategy - Design comprehensive marking scheme

  2. Use descriptive names - Clear packet/connection mark names

  3. Document purposes - Comment all mangle rules clearly

  4. Test thoroughly - Verify marking works as expected

  5. Monitor performance - Watch CPU usage with complex rules

Common patterns

Last updated

Was this helpful?