Mangle
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:
Mangle best practices
Performance optimization
Order rules efficiently - Most frequent matches first
Use passthrough wisely - Set to 'no' for final marking
Minimize regex patterns - Layer-7 detection impacts performance
Use connection marking - More efficient than per-packet marking
Combine conditions - Reduce rule count with multiple criteria
Design recommendations
Plan marking strategy - Design comprehensive marking scheme
Use descriptive names - Clear packet/connection mark names
Document purposes - Comment all mangle rules clearly
Test thoroughly - Verify marking works as expected
Monitor performance - Watch CPU usage with complex rules
Common patterns
Last updated
Was this helpful?