OPNsense Forum

English Forums => 23.7 Legacy Series => Topic started by: gstrong on September 25, 2023, 04:03:34 am

Title: How to configure static leases and dns entries programmatically?
Post by: gstrong on September 25, 2023, 04:03:34 am
Hello, I'm brand new to OPNsense, but have been running PFSense for many years and never having to dig too deep. I'd like to be able to configure my static leases and dns entries programmatically so that I may version these configs and it's very reproducible. I see that there is an "advanced" means to set configuration within /usr/local/etc/dhcpd.opnsense.d, but I have no context for how these will be loaded in and I'd like to see the surrounding config to understand what would be valid. This has led to many questions:

* What would be the advised manner to programmatically configure static mappings for dhcp?
* When a static mapping is saved in the GUI, where is this persisted in the filesystem?
* What "service manager" a.la systemd is in usage with opnsense? I stumbled across configctl and pluginctl, would like to understand the difference. Are these how opnsense services like dhcp should be managed?
* How should I achieve a similar goal, but configure dns settings such as a wildcard? Is unbounce used by default? Where is this configured in the file system?
Title: Re: How to configure static leases and dns entries programmatically?
Post by: Maurice on September 25, 2023, 01:10:36 pm
You can use the API, if that's what you're looking for:
https://docs.opnsense.org/development/api.html

The entire config is stored in a single XML file, namely /conf/config.xml. OPNsense keeps a history of this file, see System: Configuration: History.

OPNsense then generates config files for all the services, based on the settings in the XML.

Cheers
Maurice
Title: Re: How to configure static leases and dns entries programmatically?
Post by: gstrong on September 25, 2023, 02:40:40 pm
I read the api docs, can you point me to somewhere in the docs that describes how to create a static mapping? All I see are commands to manipulate leases, and to manage the service lifecycle.

Regarding the config file, is it a valid configuration method to edit that file directly? Will sense pick up changes automatically, or do I need to reload something? I am thinking the easiest way would be for me to download the file, inject my mappings into the xml, and then write it back and potentially reload the service?
Title: Re: How to configure static leases and dns entries programmatically?
Post by: Maurice on September 25, 2023, 04:56:34 pm
You're right, static mappings don't seem to be available in the API yet. Sorry, wasn't aware of this.
You can download, modify and restore the config.xml, yes. When restoring via the UI, manually reloading services shouldn't be required.