opn_add_firewall_rule
Control network traffic by creating an OPNsense firewall rule. Specify action, direction, interface, and addresses to pass, block, or reject connections.
Instructions
Create a new MVC firewall filter rule with savepoint protection where supported.
Use this when you need to add a firewall rule.
Savepoint protection applies on OPNsense < 26.7 only: there changes auto-revert in 60 seconds unless confirmed with opn_confirm_changes. OPNsense 26.7 removed the savepoint API upstream, so on 26.7+ changes apply immediately and are NOT rolled back automatically. Check opn_mcp_info first: if 'savepoint_support' is false, take a config backup with opn_download_config before changing rules that could lock you out.
IMPORTANT: This creates MVC rules (Settings > Firewall > Automation), not legacy GUI rules.
Parameters:
action: 'pass', 'block', or 'reject'
direction: 'in' or 'out'
interface: interface name (e.g. 'lan', 'wan', 'opt1')
ip_protocol: 'inet' (IPv4), 'inet6' (IPv6), or 'inet46' (dual-stack)
protocol: 'any', 'TCP', 'UDP', 'TCP/UDP', 'ICMP', etc.
source_net: source address/network or 'any'
source_not: invert source match (True = NOT source_net)
source_port: source port number or range, or empty for any
destination_net: destination address/network or 'any'
destination_not: invert destination match (True = NOT destination_net, e.g. !Private_Networks)
destination_port: port number or range (e.g. '80', '1000-2000'), or empty for any
gateway: force traffic via specific gateway (e.g. 'WAN_GW') for policy routing, or empty for default
log: enable logging for this rule (default: off)
quick: first-match wins (default: True). Set False for last-match-wins logic
sequence: rule ordering within priority group (default: 1, higher = later)
categories: comma-separated category UUIDs to assign to this rule
description: human-readable rule description
Returns: dict with 'revision' (str), 'uuid' (str), and 'result' (str).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| log | No | ||
| quick | No | ||
| action | No | pass | |
| gateway | No | ||
| protocol | No | any | |
| sequence | No | ||
| direction | No | in | |
| interface | No | lan | |
| categories | No | ||
| source_net | No | any | |
| source_not | No | ||
| description | No | ||
| ip_protocol | No | inet | |
| source_port | No | ||
| destination_net | No | any | |
| destination_not | No | ||
| destination_port | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||