Firewall and NAT

Requires OPNsense Firmware >= 26.1.1

async OPNsenseClient.get_firewall()

Retrieve all firewall and NAT rules from OPNsense.

Returns:

Normalized data returned by the related OPNsense endpoint.

Return type:

dict[str, Any]

async OPNsenseClient.toggle_firewall_rule(uuid, toggle_on_off=None)

Toggle Firewall Rule on and off.

Parameters:
  • uuid (str) – Unique identifier of the target OPNsense resource.

  • toggle_on_off (str | None, optional) – Target enabled state for the selected item.

Returns:

True when the toggle operation completes successfully; otherwise, False.

Return type:

bool

async OPNsenseClient.toggle_nat_rule(nat_rule_type, uuid, toggle_on_off=None)

Toggle NAT Rule on and off.

Parameters:
  • nat_rule_type (str) – NAT rule category to toggle.

  • uuid (str) – Unique identifier of the target OPNsense resource.

  • toggle_on_off (str | None, optional) – Target enabled state for the selected item.

Returns:

True when the toggle operation completes successfully; otherwise, False.

Return type:

bool

async OPNsenseClient.kill_states(ip_addr)

Kill the active states of the IP address.

Parameters:

ip_addr (str) – IP address whose states should be terminated.

Returns:

Mapping containing normalized fields for downstream use.

Return type:

MutableMapping[str, Any]

async OPNsenseClient.toggle_alias(alias, toggle_on_off=None)

Toggle alias on and off.

Parameters:
  • alias (str) – Alias name to toggle in firewall configuration.

  • toggle_on_off (str | None, optional) – Target enabled state for the selected item.

Returns:

True when the toggle operation completes successfully; otherwise, False.

Return type:

bool