Manage Firewall Rule
manage_firewall_ruleManage MikroTik firewall rules: add, remove, disable, or enable using comment as idempotency key; supports dry-run.
Instructions
Add, remove, disable, or enable a firewall rule on a MikroTik router. Matches addresses, ports, protocol, interfaces, interface lists, and connection/NAT state; nat rules take toAddresses/toPorts (e.g. a dst-nat port forward). Uses comment as idempotency key for deduplication and identification: a repeated add returns already_exists only when the match, NAT targets, and disabled state agree, otherwise CONFLICT (use enable/disable when only the disabled state differs). Supports dry-run mode.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chain | Yes | Firewall chain (e.g. forward, input, output, srcnat, dstnat) | |
| table | No | Firewall table to manage: filter or nat | filter |
| action | Yes | Action to perform: add, remove, disable, or enable a firewall rule | |
| dryRun | No | If true, validate and return planned changes without applying | |
| comment | No | Comment to identify the rule (used as idempotency key); omit for none | |
| dstPort | No | Destination port or range | |
| srcPort | No | Source port or range | |
| toPorts | No | NAT target port or range (nat table only) | |
| disabled | No | Whether the rule should be disabled | |
| protocol | No | Protocol to match | |
| routerId | No | Router ID; omit to use the default router. | |
| dstAddress | No | Destination address or network | |
| ruleAction | Yes | RouterOS rule action (e.g. accept, drop, reject, masquerade) | |
| srcAddress | No | Source address or network | |
| inInterface | No | Incoming interface | |
| placeBefore | No | Place the new rule before this rule ID | |
| toAddresses | No | NAT target address or range (nat table only, e.g. dst-nat) | |
| outInterface | No | Outgoing interface | |
| connectionState | No | Connection-tracking states, comma-separated, optionally negated: established,related or !invalid | |
| inInterfaceList | No | Incoming interface list, e.g. WAN or !LAN | |
| outInterfaceList | No | Outgoing interface list, e.g. WAN or !LAN | |
| confirmationToken | No | Token from a prior APPROVAL_REQUIRED response. Re-submit the identical call with this token to confirm the destructive action. | |
| connectionNatState | No | Connection NAT state to match, e.g. dstnat or !dstnat |