Batch create VLANs, Interfaces, DHCP Server, CARP, NAT, Firewall Rules, etc

Started by stif, November 20, 2023, 10:20:51 PM

Previous topic - Next topic
Hi Folks,

I had a project where i needed over 80 VLANs and CARP IPs and all the corresponding things like DHCP, manual NAT rules, Firewall Rules and Radius Users.

Since i did not want to create all of it via WebUI, i had another idea: i created a backup config.xml file via WebUI, injected all the VLANs etc by processing the config.xml with some python scripts, and then imported the config.xml file again. Works!

If you have similar plans, you might find my collection of scripts useful, so i created a github repo:
https://github.com/nett-media/opnsense-config-generator

Cheers,
Stif



Thanks for sharing, @stif.

If you are like me more familiar with shell than with Python - I just added 56 alias addresses in one go that way on Friday:
#! /bin/sh

for i in `jot 56 7`
do
uuid=`uuid`
cat <<HERE
    <vip uuid="${uuid}">
      <interface>opt2</interface>
      <mode>ipalias</mode>
      <subnet>X.Y.Z.${i}</subnet>
      <subnet_bits>32</subnet_bits>
      <gateway/>
      <noexpand>0</noexpand>
      <nobind>0</nobind>
      <password>secret</password>
      <vhid>2</vhid>
      <advbase>1</advbase>
      <advskew>0</advskew>
      <descr>External services address</descr>
    </vip>
HERE
done


X.Y.Z being the real prefix, of course.
Deciso DEC750
People who think they know everything are a great annoyance to those of us who do. (Isaac Asimov)