OPNsense
  • Home
  • Help
  • Search
  • Login
  • Register

  • OPNsense Forum »
  • Archive »
  • 22.7 Legacy Series »
  • Firewall API to manage Destination based NAT Port Forwarding
« previous next »
  • Print
Pages: [1]

Author Topic: Firewall API to manage Destination based NAT Port Forwarding  (Read 1580 times)

JamesElstone

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Firewall API to manage Destination based NAT Port Forwarding
« on: September 18, 2022, 06:14:03 pm »
Hi OPNsense Forum,

I have read up on the both the Core API and the "Firewall" plugin API, and can only find the controller for  "source_nat" that is documented.

I am wanting to dynamically control the the NAT -> Port Forward table via the API.

Also when I call the
Code: [Select]
/api/firewall/filter_base/get API, it returns an API exception error:
Code: [Select]
[internal function]: Phalcon\\Di\\Di->get('OPNsense\\\\Firewa...', NULL)
Has someone any domain knowledge in this area or can help me with this please?
Logged

JamesElstone

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
    • View Profile
Re: Firewall API to manage Destination based NAT Port Forwarding
« Reply #1 on: September 18, 2022, 08:03:27 pm »
For those who find this post and are having difficulty calling an OPNsense API, below is a full curl command posting data for reference:

Code: [Select]
curl \
-XPOST \
-H "Content-Type: application/json" \
-d '{"host": {"enabled":"1","hostname":"test","domain":"example.com","rr":"A","server":"1.2.3.4","description":"A test"}}' \
-k \
-u "yourAPIkey":"yourAPIsecret" \
https://opnsense.ip.address.or.dns.name/api/unbound/settings/addHostOverride/

The response you should get states:
Code: [Select]
{
  "result":"saved",
  "uuid":"guid_id_of_object_created"
}

Lots of people refer to it, but never in its full form in this forum. Hopefully will help others over time.
« Last Edit: September 18, 2022, 08:05:08 pm by JamesElstone »
Logged

ansibleguy

  • Newbie
  • *
  • Posts: 21
  • Karma: 2
    • View Profile
Re: Firewall API to manage Destination based NAT Port Forwarding
« Reply #2 on: September 20, 2022, 09:02:19 pm »
Hi.

FYI: If you have trouble using some OPNSense API - I've implemented many of the available ones in my project => https://github.com/ansibleguy/collection_opnsense

One could use the Ansible modules directly or read into (the code) how to use the APIs.  :D

- AnsibleGuy
« Last Edit: September 20, 2022, 09:18:14 pm by ansibleguy »
Logged

  • Print
Pages: [1]
« previous next »
  • OPNsense Forum »
  • Archive »
  • 22.7 Legacy Series »
  • Firewall API to manage Destination based NAT Port Forwarding
 

OPNsense is an OSS project © Deciso B.V. 2015 - 2024 All rights reserved
  • SMF 2.0.19 | SMF © 2021, Simple Machines
    Privacy Policy
    | XHTML | RSS | WAP2