Manage Mangle Rule
manage_mangle_ruleAdd, remove, enable, or disable RouterOS firewall mangle rules using comment as idempotency key. Preview changes with dry-run mode.
Instructions
Add, remove, enable, or disable a firewall mangle rule. ruleAction sets the action; when it is omitted, a new* value implies its own (newRoutingMark → mark-routing), otherwise accept. Each new* value is accepted only under its action. Uses comment as idempotency key: a repeated add returns already_exists only when the chain, match fields, marks, DSCP, MSS, passthrough, and the given or implied action agree, otherwise CONFLICT. Supports dry-run mode.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chain | No | Mangle chain (required on add): prerouting, input, forward, output, postrouting | |
| action | Yes | Action to perform | |
| dryRun | No | Preview changes without applying. | |
| newMss | No | MSS to set: a number or clamp-to-pmtu (ruleAction change-mss, with protocol tcp and tcpFlags syn) | |
| comment | Yes | Idempotency key — uniquely identifies this mangle rule | |
| dstPort | No | Destination port or range | |
| srcPort | No | Source port or range | |
| protocol | No | Protocol to match (e.g. tcp, udp) | |
| routerId | No | Router ID; omit to use the default router. | |
| tcpFlags | No | TCP flags to match, comma-separated, ! negates one (e.g. "syn"); needs protocol tcp | |
| dstAddress | No | Destination IP/CIDR to match | |
| ruleAction | No | Mangle action, add only. Omitted: the action of the new* value given (newRoutingMark → mark-routing, newConnectionMark → mark-connection, newPacketMark → mark-packet, newDscpValue → change-dscp, newMss → change-mss), else accept, the RouterOS default | |
| srcAddress | No | Source IP/CIDR to match | |
| inInterface | No | Incoming interface to match | |
| passthrough | No | Whether to continue matching subsequent rules | |
| newDscpValue | No | DSCP value to set, 0–63 (ruleAction change-dscp) | |
| outInterface | No | Outgoing interface to match | |
| newPacketMark | No | Packet mark to set (ruleAction mark-packet) | |
| dstAddressList | No | Destination address list name to match | |
| newRoutingMark | No | Routing mark to set (ruleAction mark-routing, chain prerouting or output) | |
| srcAddressList | No | Source address list name to match | |
| confirmationToken | No | Token from a prior APPROVAL_REQUIRED response. Re-submit the identical call with this token to confirm the destructive action. | |
| newConnectionMark | No | Connection mark to set (ruleAction mark-connection) |