REFERENCE

v6.11.0

Firewall — Mangle

Mangle rules: connection/packet/routing marks, DSCP, TTL, MSS (`/ip firewall mangle`).

Tools

create_mangle_rule

Create IPv4 Firewall Mangle Rule · Risk: write

Creates an IPv4 mangle rule (/ip firewall mangle add) — the packet-marking and header-modification table, used to mark connections/packets/routing (for policy routing, QoS and per-connection classification) or to change DSCP/TTL/MSS. For accept/drop decisions use create_filter_rule; for address translation use create_nat_rule; for IPv6 mangle use create_ipv6_mangle_rule. chain: prerouting/input/forward/output/postrouting. action: mark-connection/mark-packet/mark-routing/change-dscp/change-ttl/change-mss/add-src-to-address-list/add-dst-to-address-list/fasttrack-connection/route/set-priority/accept/etc. Set the matching new--mark field for mark- actions and keep passthrough=true so later rules can also match the same packet; for add-*-to-address-list set address_list (and optionally address_list_timeout). Full match surface: address-lists (src_address_list/dst_address_list — negate with a leading '!', e.g. dst_address_list='!IR' to route traffic NOT bound for a list), interface-lists, per_connection_classifier (PCC load-balancing), connection_nat_state, tcp_flags, dscp, layer7_protocol, time, and more. Typical policy-routing rule: chain=prerouting, src_address=, dst_address_list='!IR', action=mark-routing, new_routing_mark=, then a routing rule/route uses that table. place_before accepts a rule number or ID (*N) to control insertion position. Returns the created rule's detail including its .id.

ParameterRequiredDefinition
chainYes{"type":"string","enum":["prerouting","input","forward","output","postrouting"]}
actionYes{"type":"string","enum":["accept","add-dst-to-address-list","add-src-to-address-list","change-dscp","change-mss","change-ttl","clear-df","drop","fasttrack-connection","jump","log","mark-connection","mark-packet","mark-routing","passthrough","return","route","set-priority","sniff-pc","sniff-tzsp"]}
src_addressNo{"type":"string"}
dst_addressNo{"type":"string"}
src_portNo{"type":"string"}
dst_portNo{"type":"string"}
portNoMatch if src OR dst port matches (with protocol) {"type":"string"}
protocolNo{"type":"string"}
src_mac_addressNoSource MAC, negatable e.g. "!00:11:..." {"type":"string"}
in_interfaceNoNegatable, e.g. "!ether1" {"type":"string"}
out_interfaceNo{"type":"string"}
in_interface_listNoInterface list, negatable e.g. "!WAN" {"type":"string"}
out_interface_listNo{"type":"string"}
src_address_listNoMatch src in a named list; negate "!name" {"type":"string"}
dst_address_listNoMatch dst in a named list; negate "!name" (e.g. "!IR" routes foreign traffic) {"type":"string"}
src_address_typeNoe.g. "local", "unicast", "!local" {"type":"string"}
dst_address_typeNo{"type":"string"}
connection_markNo{"type":"string"}
packet_markNo{"type":"string"}
routing_markNo{"type":"string"}
connection_stateNoe.g. "new", "established,related", "!invalid" {"type":"string"}
connection_nat_stateNo"srcnat" / "dstnat" / "!dstnat" {"type":"string"}
connection_typeNoHelper, e.g. "sip", "ftp" {"type":"string"}
connection_bytesNoe.g. "1000000-0" (>1 MB connections) {"type":"string"}
connection_limitNoe.g. "100,32" {"type":"string"}
connection_rateNoe.g. "100k-1M" {"type":"string"}
per_connection_classifierNoPCC for load balancing, e.g. "both-addresses:2/0" {"type":"string"}
tcp_flagsNoRouterOS flag expression e.g. "syn,!ack" {"type":"string"}
dscpNoMatch incoming DSCP (0-63) {"type":"string"}
priorityNoMatch packet/queue priority (0-63) {"type":"string"}
packet_sizeNoe.g. "1500" or "0-500" {"type":"string"}
ttlNoMatch TTL, e.g. "equal:64", "less-than:10" {"type":"string"}
tcp_mssNoMatch TCP MSS, e.g. "1400-1500" or "!1460" {"type":"string"}
fragmentNoMatch second and further fragments {"type":"boolean"}
icmp_optionsNoMatch ICMP type:code, e.g. "8:0" {"type":"string"}
ipv4_optionsNoe.g. "any", "loose-source-routing", "record-route" {"type":"string"}
limitNoRate limit matcher, e.g. "50,5:packet" {"type":"string"}
dst_limitNoPer-destination rate matcher, e.g. "50,5,dst-address/1m" {"type":"string"}
contentNoMatch packets containing this text {"type":"string"}
psdNoPort scan detection, e.g. "21,3s,3,1" {"type":"string"}
layer7_protocolNoName of an /ip firewall layer7-protocol regex {"type":"string"}
ipsec_policyNoe.g. "in,ipsec" or "out,none" {"type":"string"}
nthNoe.g. "2,1" — every 2nd packet {"type":"string"}
randomNoMatch a random N% of packets (1-99) {"type":"string"}
timeNoe.g. "8h-16h,mon,tue,wed,thu,fri" {"type":"string"}
hotspotNoe.g. "auth", "!auth", "from-client" {"type":"string"}
p2pNo{"type":"string"}
new_connection_markNo{"type":"string"}
new_packet_markNo{"type":"string"}
new_routing_markNo{"type":"string"}
new_dscpNo0-63, for change-dscp {"type":"string"}
new_ttlNoe.g. "decrement", "increment", or "set:64" {"type":"string"}
new_mssNoe.g. "1440" or "clamp-to-pmtu", for change-mss {"type":"string"}
new_priorityNoPriority for action=set-priority, e.g. "4", "from-dscp", "from-ingress" {"type":"string"}
routing_tableNoRouting table for action=route {"type":"string"}
route_dstNoGateway IP for action=route {"type":"string"}
jump_targetNoTarget chain name for action=jump {"type":"string"}
sniff_targetNoCollector IP for action=sniff-tzsp/sniff-pc {"type":"string"}
sniff_target_portNoCollector UDP port for action=sniff-tzsp {"type":"string"}
address_listNoTarget list name for add-src/dst-to-address-list {"type":"string"}
address_list_timeoutNoEntry timeout for add-*-to-address-list e.g. "1h", "none" {"type":"string"}
passthroughNo{"type":"boolean"}
commentNo{"type":"string"}
disabledYes{"default":false,"type":"boolean"}
logYes{"default":false,"type":"boolean"}
log_prefixNo{"type":"string"}
place_beforeNoRule number or ID (*N) to insert before {"type":"string"}

list_mangle_rules

List IPv4 Firewall Mangle Rules · Risk: read

Lists IPv4 mangle rules (/ip firewall mangle print) — returns all rules in the mangle table with their IDs, chains, actions, and match criteria. For IPv4 filter use list_filter_rules; for IPv4 NAT use list_nat_rules; for IPv6 mangle use list_ipv6_mangle_rules. Optionally filter by chain, action, connection-mark, packet-mark, disabled, invalid, or dynamic status. Rule .id values from this output are required by get_mangle_rule, update_mangle_rule, remove_mangle_rule, move_mangle_rule, enable_mangle_rule, and disable_mangle_rule.

ParameterRequiredDefinition
chain_filterNo{"type":"string"}
action_filterNo{"type":"string"}
connection_mark_filterNo{"type":"string"}
packet_mark_filterNo{"type":"string"}
disabled_onlyYes{"default":false,"type":"boolean"}
invalid_onlyYes{"default":false,"type":"boolean"}
dynamic_onlyYes{"default":false,"type":"boolean"}

get_mangle_rule

Get IPv4 Firewall Mangle Rule Details · Risk: read

Retrieves full detail for a single IPv4 mangle rule (/ip firewall mangle print detail where .id=). Use when you need all fields of one specific rule rather than the full table listing. For the full list use list_mangle_rules; for IPv6 mangle use get_ipv6_mangle_rule. rule_id takes the .id value (e.g. "*1" or "0") returned by list_mangle_rules.

ParameterRequiredDefinition
rule_idYesRule ID from list output e.g. "*1" or "0" {"type":"string"}

update_mangle_rule

Update IPv4 Firewall Mangle Rule · Risk: write-idempotent

Updates fields on an existing IPv4 mangle rule (/ip firewall mangle set) — change chain, action, match criteria, mark values, DSCP, TTL, MSS, or flags without recreating the rule. To toggle enabled state only use enable_mangle_rule or disable_mangle_rule; for IPv6 mangle use update_ipv6_mangle_rule. rule_id takes the .id from list_mangle_rules. Pass "" (empty string) for an optional field to clear it. Returns the updated rule's full detail.

ParameterRequiredDefinition
rule_idYes{"type":"string"}
chainNo{"type":"string"}
actionNo{"type":"string"}
src_addressNo{"type":"string"}
dst_addressNo{"type":"string"}
src_portNo{"type":"string"}
dst_portNo{"type":"string"}
portNo{"type":"string"}
protocolNo{"type":"string"}
src_mac_addressNo{"type":"string"}
in_interfaceNo{"type":"string"}
out_interfaceNo{"type":"string"}
in_interface_listNo{"type":"string"}
out_interface_listNo{"type":"string"}
src_address_listNoNegate with "!name" (e.g. "!IR") {"type":"string"}
dst_address_listNoNegate with "!name" (e.g. "!IR") {"type":"string"}
src_address_typeNo{"type":"string"}
dst_address_typeNo{"type":"string"}
connection_markNo{"type":"string"}
packet_markNo{"type":"string"}
routing_markNo{"type":"string"}
connection_stateNo{"type":"string"}
connection_nat_stateNo{"type":"string"}
connection_typeNo{"type":"string"}
connection_bytesNo{"type":"string"}
connection_limitNo{"type":"string"}
connection_rateNo{"type":"string"}
per_connection_classifierNo{"type":"string"}
tcp_flagsNo{"type":"string"}
dscpNo{"type":"string"}
priorityNo{"type":"string"}
packet_sizeNo{"type":"string"}
ttlNo{"type":"string"}
tcp_mssNo{"type":"string"}
fragmentNo{"type":"boolean"}
icmp_optionsNo{"type":"string"}
ipv4_optionsNo{"type":"string"}
limitNo{"type":"string"}
dst_limitNo{"type":"string"}
contentNo{"type":"string"}
psdNo{"type":"string"}
layer7_protocolNo{"type":"string"}
ipsec_policyNo{"type":"string"}
nthNo{"type":"string"}
randomNo{"type":"string"}
timeNo{"type":"string"}
hotspotNo{"type":"string"}
p2pNo{"type":"string"}
new_connection_markNo{"type":"string"}
new_packet_markNo{"type":"string"}
new_routing_markNo{"type":"string"}
new_dscpNo{"type":"string"}
new_ttlNo{"type":"string"}
new_mssNo{"type":"string"}
new_priorityNo{"type":"string"}
routing_tableNo{"type":"string"}
route_dstNo{"type":"string"}
jump_targetNo{"type":"string"}
sniff_targetNo{"type":"string"}
sniff_target_portNo{"type":"string"}
address_listNo{"type":"string"}
address_list_timeoutNo{"type":"string"}
passthroughNo{"type":"boolean"}
commentNo{"type":"string"}
disabledNo{"type":"boolean"}
logNo{"type":"boolean"}
log_prefixNo{"type":"string"}

remove_mangle_rule

Remove IPv4 Firewall Mangle Rule · Risk: destructive

Permanently deletes an IPv4 mangle rule (/ip firewall mangle remove) — verifies the rule exists first, then removes it. To only deactivate without deleting use disable_mangle_rule; for IPv6 mangle use remove_ipv6_mangle_rule. rule_id takes the .id from list_mangle_rules. Returns confirmation on success or a not-found message if the ID is absent.

ParameterRequiredDefinition
rule_idYes{"type":"string"}

move_mangle_rule

Move IPv4 Firewall Mangle Rule · Risk: write-idempotent

Reorders an IPv4 mangle rule to a specific position (/ip firewall mangle move) — mangle rules are evaluated top-down, so position controls which rules fire first. For IPv4 filter reordering use move_filter_rule; for IPv6 mangle use move_ipv6_mangle_rule. rule_id takes the .id from list_mangle_rules; destination is the 0-based target index. Verifies the rule exists before moving.

ParameterRequiredDefinition
rule_idYes{"type":"string"}
destinationYes0-based target position index {"type":"integer","minimum":-9007199254740991,"maximum":9007199254740991}

enable_mangle_rule

Enable IPv4 Firewall Mangle Rule · Risk: write-idempotent

Enables a disabled IPv4 mangle rule (/ip firewall mangle set disabled=no) so it participates in packet processing again. To deactivate use disable_mangle_rule; to delete permanently use remove_mangle_rule; for IPv6 mangle use enable_ipv6_mangle_rule. rule_id takes the .id from list_mangle_rules. Returns the updated rule's detail.

ParameterRequiredDefinition
rule_idYes{"type":"string"}

disable_mangle_rule

Disable IPv4 Firewall Mangle Rule · Risk: write-idempotent

Disables an active IPv4 mangle rule (/ip firewall mangle set disabled=yes) — the rule remains in the table but is skipped during packet processing. To re-enable use enable_mangle_rule; to delete permanently use remove_mangle_rule; for IPv6 mangle use disable_ipv6_mangle_rule. rule_id takes the .id from list_mangle_rules. Returns the updated rule's detail.

ParameterRequiredDefinition
rule_idYes{"type":"string"}

On this page