Home
Help
Search
Login
Register
OPNsense Forum
»
English Forums
»
Tutorials and FAQs
»
Add dhcp4 statics leases by batch
« previous
next »
Print
Pages: [
1
]
Author
Topic: Add dhcp4 statics leases by batch (Read 4548 times)
ble
Newbie
Posts: 4
Karma: 0
Add dhcp4 statics leases by batch
«
on:
May 10, 2023, 01:08:31 pm »
Hello everybody,
I work with opnsense 23.1.6 the plugin os-firewall is installed.
I look for add dhcp4 statics leases by batch.
The best way for me should be by API but i don't find.
Have you got a idea for this?
best regards
Logged
yourfriendarmando
Full Member
Posts: 103
Karma: 8
Re: Add dhcp4 statics leases by batch
«
Reply #1 on:
June 17, 2023, 11:02:12 am »
I have used something like a spreadsheet to do string concatenation on the part of the config where your DHCP IPs are reserved.
The required fields are MAC, Hostname, and IP
Optional description.
Do this for the scope you want, create a new XML, and load it. Take plenty of backups.
Logged
ble
Newbie
Posts: 4
Karma: 0
Re: Add dhcp4 statics leases by batch
«
Reply #2 on:
June 19, 2023, 08:19:54 am »
hello,
Thx for your reply,
Sorry, it is too short for my understanding!
Could you write a little tuto if you have a time.
Best regards
Logged
yourfriendarmando
Full Member
Posts: 103
Karma: 8
Re: Add dhcp4 statics leases by batch
«
Reply #3 on:
June 22, 2023, 08:15:18 am »
Excellent
I was able to create something I can use myself for future batch DHCP reservations:
To run this batch load, make sure you have the interface configured, enable DHCP server on it, have it enabled and defined with a scope and your global options. I don't normally use per host options, that are already covered in the global scope settings. Create at least one static DHCP IP reservation. The batch load of IPs should be outside of your scope, it tends to work better that way. Take a backup of the running config.
This can probably be adapted for ipv6, but this is a good start.
Please see the attached OpenDocument Spreadsheet. You should be able to open it via Libre/OpenOffice, Excel, GNumeric, Numbers, etc.
You can basically adapt your inventory list with the required columns, then the E column does nested string substitutions for each field. Drag the formula down to cover all of your hosts. Copy the text over to a text editor.
Edit a backup XML config file, look for the last <staticmap> , paste the text after this line. It should look something like this:
</staticmap>
<staticmap>
<mac>52:14:55:11:92:0e</mac>
<ipaddr>10.240.0.14</ipaddr>
<hostname>somePreviousHost</hostname>
<descr>Some description if you use it</descr>
<winsserver/>
<dnsserver/>
<ntpserver/>
</staticmap>
<staticmap><mac>55:44:33:22:11:00</mac><ipaddr>10.240.0.20</ipaddr><hostname>batch-01</hostname><descr>desktop sn: 000001</descr><winsserver/><dnsserver/><ntpserver/></staticmap>
<staticmap><mac>55:44:33:22:11:01</mac><ipaddr>10.240.0.21</ipaddr><hostname>batch-02</hostname><descr>desktop sn: 000002</descr><winsserver/><dnsserver/><ntpserver/></staticmap>
<staticmap><mac>55:44:33:22:11:02</mac><ipaddr>10.240.0.22</ipaddr><hostname>batch-03</hostname><descr>desktop sn: 000003</descr><winsserver/><dnsserver/><ntpserver/></staticmap>
<staticmap><mac>55:44:33:22:11:03</mac><ipaddr>10.240.0.23</ipaddr><hostname>batch-04</hostname><descr>desktop sn: 000004</descr><winsserver/><dnsserver/><ntpserver/></staticmap>
...
</opt2>
Take one more backup. In the menu for "Restore Area", pick DHCP Server, you don't have to Reboot. Find the modified config file, and load it . Go check out the DHCP settings for the affected interface, and you should see you new batch.
Logged
42network
Newbie
Posts: 6
Karma: 0
Re: Add dhcp4 statics leases by batch
«
Reply #4 on:
September 18, 2023, 04:20:52 pm »
Love it! I have a very similar spreadsheet that I originally used for the same purpose with Tomato and I added a column for the OPNsense XML format as well.
Now why is it that such a very simple idea of using a spreadsheet to manage complex lists of DHCP reservations cannot be automated, or semi-automated? Are there any IPAM OPNsense plugins that could do this job?
Thanks
Logged
Print
Pages: [
1
]
« previous
next »
OPNsense Forum
»
English Forums
»
Tutorials and FAQs
»
Add dhcp4 statics leases by batch