OPNsense Forum

English Forums => Tutorials and FAQs => Topic started by: stif on November 20, 2023, 10:20:51 pm

Title: Batch create VLANs, Interfaces, DHCP Server, CARP, NAT, Firewall Rules, etc
Post by: stif on November 20, 2023, 10:20:51 pm
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
Title: Re: Batch create VLANs, Interfaces, DHCP Server, CARP, NAT, Firewall Rules, etc
Post by: cookiemonster on November 21, 2023, 10:22:19 am
Very nice. Thanks for sharing.
Title: Re: Batch create VLANs, Interfaces, DHCP Server, CARP, NAT, Firewall Rules, etc
Post by: bucky2780 on December 04, 2023, 07:57:01 pm
cool stuff...
Title: Re: Batch create VLANs, Interfaces, DHCP Server, CARP, NAT, Firewall Rules, etc
Post by: Patrick M. Hausen on December 04, 2023, 08:14:19 pm
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:
Code: [Select]
#! /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.