REFERENCE

v6.11.0

Firewall — Filter

Filter rules and a guided basic setup (`/ip firewall filter`).

Tools

create_filter_rule

Create Firewall Filter Rule · Risk: write

Creates an IPv4 firewall FILTER rule (/ip firewall filter) — the accept/drop/reject decision table for traffic TO the router (chain=input), THROUGH it (forward) or FROM it (output). Use this to allow or block traffic. For address translation use the NAT tools, for packet marking use mangle, for pre-connection-tracking drops use raw, and for IPv6 use create_ipv6_filter_rule. chain also accepts a CUSTOM sub-chain name (e.g. detect-portscan) reached by an action=jump rule, and action supports add-src-to-address-list / add-dst-to-address-list (with address_list + address_list_timeout) for tagging/detection rules. Rule order matters (first match wins) — use place_before or move_filter_rule to position it. Returns the created rule's detail including its .id. connection_state: comma-separated e.g. "established,related,new,invalid". limit: RouterOS rate/burst string e.g. "10,5:packet" or "10/1s:packet". tcp_flags: RouterOS flag expression e.g. "syn,!ack". place_before: rule number or ID (*N) to insert before e.g. "0" or "*3".

ParameterRequiredDefinition
chainYesThe built-in input, forward, or output chain — OR a custom sub-chain name (e.g. detect-portscan). A custom chain runs only when a rule with action=jump and jump-target= sends traffic into it; use this to build tagging/detection sub-chains. {"type":"string"}
actionYes{"type":"string","enum":["accept","drop","reject","jump","log","passthrough","return","tarpit","fasttrack-connection","add-src-to-address-list","add-dst-to-address-list"]}
src_addressNo{"type":"string"}
dst_addressNo{"type":"string"}
src_portNo{"type":"string"}
dst_portNo{"type":"string"}
protocolNo{"type":"string"}
in_interfaceNoMatch by inbound interface NAME (e.g. ether1, pppoe-out1) — NOT a chain and NOT an interface list. For an interface list use in_interface_list. {"type":"string"}
out_interfaceNoMatch by outbound interface NAME (e.g. ether1, pppoe-out1) — NOT a chain and NOT an interface list. For an interface list use out_interface_list. {"type":"string"}
connection_stateNoComma-separated e.g. "established,related,new,invalid" {"type":"string"}
connection_nat_stateNo{"type":"string"}
src_address_listNo{"type":"string"}
dst_address_listNo{"type":"string"}
limitNoRouterOS rate/burst string e.g. "10,5:packet" {"type":"string"}
tcp_flagsNoRouterOS flag expression e.g. "syn,!ack" {"type":"string"}
src_mac_addressNoSource MAC, supports ! and mask e.g. "00:11:..." {"type":"string"}
in_interface_listNoMatch by inbound interface list name {"type":"string"}
out_interface_listNoMatch by outbound interface list name {"type":"string"}
portNoMatch src OR dst port(s) (protocol-agnostic) {"type":"string"}
connection_markNoMatch packets with this connection mark {"type":"string"}
packet_markNoMatch packets with this packet mark {"type":"string"}
routing_markNoMatch packets with this routing mark {"type":"string"}
connection_typeNoConntrack helper type e.g. "ftp,sip" {"type":"string"}
connection_bytesNoTotal conn bytes range e.g. "1000000-0" {"type":"string"}
connection_limitNoPer-address conn limit e.g. "100,32" {"type":"string"}
connection_rateNoConnection rate range e.g. "0-100k" {"type":"string"}
contentNoMatch a literal string in the packet payload {"type":"string"}
dscpNoMatch DSCP/TOS value 0-63 {"type":"string"}
layer7_protocolNoMatch a /ip firewall layer7-protocol name {"type":"string"}
packet_sizeNoPacket size or range in bytes e.g. "0-1500" {"type":"string"}
ipsec_policyNoIPsec policy match e.g. "in,ipsec" or "out,none" {"type":"string"}
ttlNoTTL match e.g. "equal:64" or "less-than:5" {"type":"string"}
nthNoMatch every Nth packet e.g. "2,1" {"type":"string"}
timeNoTime/day match e.g. "8h-16h,mon,tue,wed" {"type":"string"}
randomNoMatch a packet randomly with given probability (1-99) {"type":"string"}
tcp_mssNoTCP MSS match e.g. "1300-1536" or "!1460" {"type":"string"}
fragmentNoMatch non-first IP fragments {"type":"boolean"}
src_address_typeNoSource address type e.g. "unicast","local" {"type":"string"}
dst_address_typeNoDest address type e.g. "broadcast","multicast" {"type":"string"}
hotspotNoHotspot match e.g. "auth","from-client","local-dst" {"type":"string"}
icmp_optionsNoICMP type:code match e.g. "8:0" {"type":"string"}
priorityNoMatch packets by priority (0-63) set internally {"type":"string"}
jump_targetNoTarget chain name when action=jump {"type":"string"}
reject_withNoICMP/TCP reject response when action=reject {"type":"string"}
address_listNoList name for add-src-to-address-list / add-dst-to-address-list actions {"type":"string"}
address_list_timeoutNoTimeout for the address-list entry e.g. "1d" or "none" {"type":"string"}
commentNo{"type":"string"}
disabledYes{"default":false,"type":"boolean"}
logYes{"default":false,"type":"boolean"}
log_prefixNo{"type":"string"}
place_beforeNoInsert before this position. Either a bare ordinal/row number (e.g. "0", "13") OR a CURRENT internal .id ("*N") from list_filter_rules. Note: a "*N" .id is hexadecimal and reassigned over time — it is NOT the row number, so "*13" ≠ the 13th rule. {"type":"string"}

list_filter_rules

List Firewall Filter Rules · Risk: read

Lists IPv4 firewall FILTER rules (/ip firewall filter) in chain/match order — each with its .id, chain, action, matchers, comment and packet/byte counters. This is the accept/drop decision table, NOT NAT (address translation), mangle (marking) or raw (pre-conntrack); for IPv6 use list_ipv6_filter_rules. Optional filters narrow by chain, action, src/dst address, protocol or interface, or to only disabled/invalid/dynamic rules.

ParameterRequiredDefinition
chain_filterNo{"type":"string"}
action_filterNo{"type":"string"}
src_address_filterNo{"type":"string"}
dst_address_filterNo{"type":"string"}
protocol_filterNo{"type":"string"}
interface_filterNo{"type":"string"}
disabled_onlyYes{"default":false,"type":"boolean"}
invalid_onlyYes{"default":false,"type":"boolean"}
dynamic_onlyYes{"default":false,"type":"boolean"}

get_filter_rule

Get Firewall Filter Rule · Risk: read

Gets the full detail of one IPv4 firewall FILTER rule (/ip firewall filter) by id — every matcher, action, counter and flag. For IPv6 use get_ipv6_filter_rule. rule_id: preferably the .id from list_filter_rules e.g. "*1F". A bare number like "3" is read as the positional ROW INDEX and resolved to whatever .id currently sits there — it is never treated as .id=*3, since a *N id is hex and reassigned over time. Row positions shift whenever a rule is added, removed or moved, so prefer the .id.

ParameterRequiredDefinition
rule_idYesRule .id e.g. "*1F", or bare position number e.g. "3" {"type":"string"}

update_filter_rule

Update Firewall Filter Rule · Risk: write-idempotent

Updates an existing IPv4 firewall FILTER rule (/ip firewall filter) in place and returns its new detail. To reorder it use move_filter_rule; to toggle it on/off use enable_filter_rule / disable_filter_rule; for IPv6 use update_ipv6_filter_rule. rule_id: the .id from list_filter_rules e.g. "*1" or "0". connection_state: comma-separated e.g. "established,related". limit: RouterOS rate string e.g. "10,5:packet". tcp_flags: RouterOS flag expression e.g. "syn,!ack". Pass "" to clear an optional field (e.g. src_address="").

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"}
protocolNo{"type":"string"}
in_interfaceNoInbound interface NAME (e.g. ether1) — not a chain; use in_interface_list for a list. {"type":"string"}
out_interfaceNoOutbound interface NAME (e.g. ether1) — not a chain; use out_interface_list for a list. {"type":"string"}
connection_stateNo{"type":"string"}
connection_nat_stateNo{"type":"string"}
src_address_listNo{"type":"string"}
dst_address_listNo{"type":"string"}
limitNo{"type":"string"}
tcp_flagsNo{"type":"string"}
src_mac_addressNo{"type":"string"}
in_interface_listNo{"type":"string"}
out_interface_listNo{"type":"string"}
portNo{"type":"string"}
connection_markNo{"type":"string"}
packet_markNo{"type":"string"}
routing_markNo{"type":"string"}
connection_typeNo{"type":"string"}
connection_bytesNo{"type":"string"}
connection_limitNo{"type":"string"}
connection_rateNo{"type":"string"}
contentNo{"type":"string"}
dscpNo{"type":"string"}
layer7_protocolNo{"type":"string"}
packet_sizeNo{"type":"string"}
ipsec_policyNo{"type":"string"}
ttlNo{"type":"string"}
nthNo{"type":"string"}
timeNo{"type":"string"}
randomNo{"type":"string"}
tcp_mssNo{"type":"string"}
fragmentNo{"type":"boolean"}
src_address_typeNo{"type":"string"}
dst_address_typeNo{"type":"string"}
hotspotNo{"type":"string"}
icmp_optionsNo{"type":"string"}
priorityNo{"type":"string"}
jump_targetNo{"type":"string"}
reject_withNo{"type":"string"}
address_listNo{"type":"string"}
address_list_timeoutNo{"type":"string"}
commentNo{"type":"string"}
disabledNo{"type":"boolean"}
logNo{"type":"boolean"}
log_prefixNo{"type":"string"}

remove_filter_rule

Remove Firewall Filter Rule · Risk: destructive

Permanently deletes one IPv4 firewall FILTER rule (/ip firewall filter) by id (verifies it exists first). To keep a rule but stop it matching, use disable_filter_rule instead; for IPv6 use remove_ipv6_filter_rule. rule_id: the .id from list_filter_rules e.g. "*1" or "0".

ParameterRequiredDefinition
rule_idYes{"type":"string"}

move_filter_rule

Move Firewall Filter Rule · Risk: write-idempotent

Reorders one IPv4 firewall FILTER rule (/ip firewall filter) within its chain. Order is significant — the first matching rule decides the packet's fate, so position an accept before a broad drop. For IPv6 use move_ipv6_filter_rule. rule_id: the .id from list_filter_rules e.g. "*1" or "0". destination: 0-based target position index.

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

enable_filter_rule

Enable Firewall Filter Rule · Risk: write-idempotent

Enables (un-disables) one IPv4 firewall FILTER rule (/ip firewall filter) by id so it takes effect again. Idempotent. For IPv6 use enable_ipv6_filter_rule. rule_id: the .id from list_filter_rules e.g. "*1" or "0".

ParameterRequiredDefinition
rule_idYes{"type":"string"}

disable_filter_rule

Disable Firewall Filter Rule · Risk: write-idempotent

Disables one IPv4 firewall FILTER rule (/ip firewall filter) by id WITHOUT deleting it, so it stops matching traffic but stays in the config. Idempotent and reversible with enable_filter_rule. For IPv6 use disable_ipv6_filter_rule. rule_id: the .id from list_filter_rules e.g. "*1" or "0".

ParameterRequiredDefinition
rule_idYes{"type":"string"}

create_basic_firewall_setup

Create Basic Firewall Setup · Risk: dangerous

Appends a starter set of IPv4 input-chain FILTER rules (/ip firewall filter): accept established/related, drop invalid, accept ICMP, and a management allow — a safe baseline for a fresh router. DANGEROUS: adds several live rules at once and is NOT idempotent (running twice duplicates them). Ensure a management-allow rule precedes any drop, or you can lock yourself out — prefer plan_changes/apply_plan (Safe Mode) to stage it safely.

No tool-specific parameters.

On this page