REFERENCE

v6.11.0

Firewall — NAT

NAT rules: src/dst-nat, masquerade, redirect (`/ip firewall nat`).

Tools

create_nat_rule

Create IPv4 Firewall NAT Rule · Risk: write

Creates an IPv4 NAT rule (/ip firewall nat add) — the address-translation table for outbound masquerade or source NAT (chain=srcnat: actions masquerade, src-nat, netmap, same) and for port-forwarding or destination NAT (chain=dstnat: actions dst-nat, redirect, netmap, same). For accept/drop/reject packet filtering use create_filter_rule; for IPv6 NAT use create_ipv6_nat_rule. Returns the created rule's detail including its .id. to_addresses: single IP or range e.g. "10.0.0.1" or "10.0.0.1-10.0.0.10". to_ports: single port or range e.g. "8080" or "8080-8090". place_before: rule number or ID (*N) to insert before e.g. "0" or "*3".

ParameterRequiredDefinition
chainYes{"type":"string","enum":["srcnat","dstnat"]}
actionYes{"type":"string"}
src_addressNo{"type":"string"}
dst_addressNo{"type":"string"}
src_portNo{"type":"string"}
dst_portNo{"type":"string"}
protocolNo{"type":"string"}
in_interfaceNoNegatable, e.g. "!ether1" {"type":"string"}
out_interfaceNo{"type":"string"}
in_interface_listNoInterface list, e.g. "WAN" or "!LAN" {"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" {"type":"string"}
connection_markNo{"type":"string"}
connection_nat_stateNo"srcnat" / "dstnat" / "!dstnat" {"type":"string"}
connection_stateNoMatch conn state, e.g. "new" / "established,related" / "!invalid" {"type":"string"}
connection_typeNoMatch helper-detected conn type, e.g. "ftp" / "sip" {"type":"string"}
connection_bytesNoTotal conn bytes range, e.g. "1000000-" {"type":"string"}
connection_limitNoPer-address conn limit, e.g. "100,32" {"type":"string"}
connection_rateNoConn rate range, e.g. "0-100k" {"type":"string"}
portNoMatch src OR dst port (any protocol with ports) {"type":"string"}
src_mac_addressNoSource MAC, negate "!AA:BB:.." {"type":"string"}
packet_markNoMatch a packet mark set in mangle {"type":"string"}
routing_markNoMatch a routing mark set in mangle {"type":"string"}
src_address_typeNo"unicast" / "local" / "broadcast" / etc. {"type":"string"}
dst_address_typeNo"unicast" / "local" / "broadcast" / etc. {"type":"string"}
in_bridge_portNoIngress bridge port (bridge-filtered) {"type":"string"}
out_bridge_portNoEgress bridge port (bridge-filtered) {"type":"string"}
in_bridge_port_listNoIngress bridge port list {"type":"string"}
out_bridge_port_listNoEgress bridge port list {"type":"string"}
icmp_optionsNoICMP type:code, e.g. "8:0" {"type":"string"}
ipsec_policyNoe.g. "in,ipsec" / "out,none" {"type":"string"}
layer7_protocolNoName of an /ip firewall layer7-protocol {"type":"string"}
contentNoMatch a literal string in the packet payload {"type":"string"}
dscpNoDSCP value 0-63 {"type":"string"}
priorityNoMatch packet priority (queue/VLAN) {"type":"string"}
tcp_flagsNoe.g. "syn,!ack" {"type":"string"}
tcp_mssNoTCP MSS range, e.g. "1440-1500" {"type":"string"}
packet_sizeNoPacket size range, e.g. "1500" or "0-500" {"type":"string"}
limitNoRate limit, e.g. "10,5:packet" {"type":"string"}
nthNoEvery Nth packet, e.g. "2,0" {"type":"string"}
psdNoPort-scan detection params {"type":"string"}
randomNoMatch packet randomly with given probability % (1-99) {"type":"string"}
per_connection_classifierNoPCC classifier, e.g. "both-addresses:2/0" {"type":"string"}
timeNoTime/day matcher, e.g. "8h-16h,mon,tue,wed,thu,fri" {"type":"string"}
ttlNoIP TTL matcher, e.g. "equal:64" {"type":"string"}
hotspotNoHotspot state, e.g. "auth" / "!auth" {"type":"string"}
jump_targetNoTarget chain name when action=jump {"type":"string"}
address_listNoList name for action=add-src-to-address-list / add-dst-to-address-list {"type":"string"}
address_list_timeoutNoTimeout for the address-list entry, e.g. "1h" or "none" {"type":"string"}
fragmentNoMatch non-first IP fragments {"type":"boolean"}
to_addressesNoSingle IP or range e.g. "10.0.0.1" or "10.0.0.1-10.0.0.10" {"type":"string"}
to_portsNoSingle port or range e.g. "8080" or "8080-8090" {"type":"string"}
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 e.g. "0" or "*3" {"type":"string"}

list_nat_rules

List IPv4 Firewall NAT Rules · Risk: read

Lists IPv4 NAT rules (/ip firewall nat print) — returns all srcnat and dstnat rules, optionally filtered by chain, action, address, protocol, or interface. Use the returned .id values with get_nat_rule, update_nat_rule, move_nat_rule, enable_nat_rule, disable_nat_rule, and remove_nat_rule. For IPv6 NAT rules use list_ipv6_nat_rules; for IPv4 filter rules use list_filter_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"}

get_nat_rule

Get IPv4 Firewall NAT Rule Details · Risk: read

Fetches full detail for a single IPv4 NAT rule (/ip firewall nat print detail where .id=<rule_id>). Returns chain, action, address matchers, port matchers, to-addresses, to-ports, and rule flags for that rule. rule_id takes the .id from list_nat_rules e.g. "*1" or "0". To list all rules use list_nat_rules; for IPv6 NAT use get_ipv6_nat_rule.

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

update_nat_rule

Update IPv4 Firewall NAT Rule · Risk: write-idempotent

Modifies fields of an existing IPv4 NAT rule (/ip firewall nat set) without recreating it. rule_id takes the .id from list_nat_rules e.g. "*1" or "0"; returns the updated rule's full detail. For IPv6 NAT use update_ipv6_nat_rule; to toggle enabled state only use enable_nat_rule or disable_nat_rule. to_addresses: single IP or range e.g. "10.0.0.1" or "10.0.0.1-10.0.0.10". to_ports: single port or range e.g. "8080" or "8080-8090". Pass "" to clear an optional field.

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_interfaceNo{"type":"string"}
out_interfaceNo{"type":"string"}
in_interface_listNo{"type":"string"}
out_interface_listNo{"type":"string"}
src_address_listNoNegate with "!name" {"type":"string"}
dst_address_listNoNegate with "!name" {"type":"string"}
connection_markNo{"type":"string"}
connection_nat_stateNo{"type":"string"}
connection_stateNo{"type":"string"}
connection_typeNo{"type":"string"}
connection_bytesNo{"type":"string"}
connection_limitNo{"type":"string"}
connection_rateNo{"type":"string"}
portNo{"type":"string"}
src_mac_addressNo{"type":"string"}
packet_markNo{"type":"string"}
routing_markNo{"type":"string"}
src_address_typeNo{"type":"string"}
dst_address_typeNo{"type":"string"}
in_bridge_portNo{"type":"string"}
out_bridge_portNo{"type":"string"}
in_bridge_port_listNo{"type":"string"}
out_bridge_port_listNo{"type":"string"}
icmp_optionsNo{"type":"string"}
ipsec_policyNo{"type":"string"}
layer7_protocolNo{"type":"string"}
contentNo{"type":"string"}
dscpNo{"type":"string"}
priorityNo{"type":"string"}
tcp_flagsNo{"type":"string"}
tcp_mssNo{"type":"string"}
packet_sizeNo{"type":"string"}
limitNo{"type":"string"}
nthNo{"type":"string"}
psdNo{"type":"string"}
randomNo{"type":"string"}
per_connection_classifierNo{"type":"string"}
timeNo{"type":"string"}
ttlNo{"type":"string"}
hotspotNo{"type":"string"}
jump_targetNo{"type":"string"}
address_listNo{"type":"string"}
address_list_timeoutNo{"type":"string"}
fragmentNo{"type":"boolean"}
to_addressesNo{"type":"string"}
to_portsNo{"type":"string"}
commentNo{"type":"string"}
disabledNo{"type":"boolean"}
logNo{"type":"boolean"}
log_prefixNo{"type":"string"}

remove_nat_rule

Remove IPv4 Firewall NAT Rule · Risk: destructive

Permanently deletes an IPv4 NAT rule (/ip firewall nat remove). Verifies existence with a count-only check before deleting; returns an error if the rule is not found. rule_id takes the .id from list_nat_rules e.g. "*1" or "0". To disable without deleting use disable_nat_rule; for IPv6 NAT use remove_ipv6_nat_rule.

ParameterRequiredDefinition
rule_idYes{"type":"string"}

move_nat_rule

Move IPv4 Firewall NAT Rule · Risk: write-idempotent

Reorders an IPv4 NAT rule within the NAT chain (/ip firewall nat move). NAT rules are evaluated top to bottom and the first match wins, so position matters. rule_id takes the .id from list_nat_rules e.g. "*1" or "0"; destination is the 0-based target position index. For filter rule reordering use move_filter_rule; for IPv6 NAT reordering use move_ipv6_nat_rule.

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

enable_nat_rule

Enable IPv4 Firewall NAT Rule · Risk: write-idempotent

Re-enables a disabled IPv4 NAT rule (/ip firewall nat set disabled=no). rule_id takes the .id from list_nat_rules e.g. "*1" or "0"; returns the updated rule detail. To disable use disable_nat_rule; to edit other fields use update_nat_rule; for IPv6 NAT use enable_ipv6_nat_rule.

ParameterRequiredDefinition
rule_idYes{"type":"string"}

disable_nat_rule

Disable IPv4 Firewall NAT Rule · Risk: write-idempotent

Disables an active IPv4 NAT rule without removing it (/ip firewall nat set disabled=yes). rule_id takes the .id from list_nat_rules e.g. "*1" or "0"; returns the updated rule detail after disabling. To re-enable use enable_nat_rule; to permanently delete use remove_nat_rule; for IPv6 NAT use disable_ipv6_nat_rule.

ParameterRequiredDefinition
rule_idYes{"type":"string"}

On this page