A Tour of My Overcomplicated Router
I’ve been fed up with pfSense ever since my update to 2.8.0 stable caused a kernel panic at boot due to the presence of an iwm3160 WiFi card. And to top it off, I then found that NetGate stopped offering offline install media, and has instead started forcing Community Edition users to use this awful installer that you must purchase (at no cost) from their online shop.
Recently, I had some very strange issues with my pfSense host, seemingly caused by the unfortunate interruption of a post-upgrade boot script (whoops!). It appeared to be stuck between the older version and the newer one, and neither using the UI nor simple shell commands to complete the update appeared effective. This was just the excuse I needed to finally try out OPNSense. Due to the last pfSense kerfuffle, I kept a secondary hardware router configured and ready to tag in. I’m happy to report that it did just fine while I set up its OPNSense replacement!
Besides changing the router OS, I realized that perhaps running a router on bare metal isn’t the best idea. I would’ve had a much better day if I could’ve rolled back to a previous snapshot after the botched pfSense update. So, I contrived the following plan - my router hardware will run a Proxmox host OS with a single OPNSense VM served by it. My router hardware only has two NICs, so I grabbed a USB Ethernet adapter to use as Proxmox’s management interface, while bonding the onboard NICs to the OPNSense VM. Unfortunately the CPU/BIOS have no mention of PCI pass-through, so I’m stuck bridging the interfaces between the hypervisor and VM. This led to an interesting problem for traffic tagged for VLAN 1, as Proxmox mangled it before passing it to the OPNSense container through the network bridge. I thus changed the tag number for that VLAN!
Building custom Proxmox install media
Ideally, this installation would be as close to “declarative” as I could get. You can use the proxmox-auto-install-assistant to modify an existing Proxmox install image for custom, unattended installation. Unfortunately for OPNSense, a similar tool for seeding a configuration does not exist. Using proxmox-auto-install-assistant, I seeded an answer.toml file with the typical host information. I decided to use a static IP on the management interface that’s on the LAN network the router VM will manage. The router VM would assign a static DHCP lease for it, so it thinks it’s in charge. Of particular importance in the custom Proxmox install media is the on-first-boot script. The install media limits it to 1MiB in size, however that’s more than enough for my purposes. The script performs typical Proxmox customization, defines the bridge interfaces for the soon to be installed install OPNSense VM, locates and copies the OPNSense VM image of OPNSense from the install media to a local disk, and instantiates it into a VM.
You may have noticed that I skipped over defining how I carried the OPNSense VM with the install media. That’s because I’m not happy with my current approach. Options include using an additional USB device or using another partition on the install media. However at this time I’m using a gross build pipeline that installs the VM image directly into the Proxmox install image with xorriso. Hopefully by the time I publish my process I will have found a better way to manage this.
You might ask - where’d I get the OPNSense VM image from to begin with? To kick-start this process, I created an OPNSense VM and customized it by hand to my liking. However, this did not feel “declarative” enough. Ideally I’d be able to directly go from an XML config file to an OPNSense VM image. Although OPNSense doesn’t let you customize install media or perform any sort of unattended installation, you can provide a config file at the start of the install process. With a little bit of scripting you could probably jerry-rig an “unattended” install of a config file with known settings in a VM environment (assuming OPNSense never changes their installer prompts). I decided to not do that. Instead, I set up an OPNSense build environment that can spit out a pre-configured OPNSense VM image.
Building a customized OPNSense image
As a POC, I was able to construct a build environment using a QEMU VM of FreeBSD 15.1 with opnsense-tools installed, as directed by OPNSense’s build instructions. I inject the custom XML config and build targeting a qcow2 VM image.
This approach is highly artisinal, and I do not think it’s worth it! As nice as it is that I can generate a VM image from an OPNSense config file, the requirement of managing this build environment and build process just doesn’t seem worth it, compared to the painstaking need to perform attended installation of OPNSense, utilizing its config importer.
If I ever do want to automate this step, I will likely switch to building a VM image with QEMU by running the OPNSense installer manually. In all honesty, I hope to never have to auto-deploy an OPNSense VM! At the end of the day I will still maintain images of working OPNSense VMs.
Conclusion
In truth, I wish I didn’t have to do any of this, but I’ve been burned twice now by running a router OS on bare metal, and I simply don’t trust them anymore. I’m glad that I was finally given the kick I needed to get off of pfSense. Although I didn’t investigate a config migrator to automate moving from pfSense to OPNSense, they do exist. So far I’ve been quite happy with OPNSense, and have not had issues with Proxmox. I hope it stays that way.
Although I have no interest in sharing my OPNSense configuration, the build pipeline components are useful, and I intend to share them eventually. I’ll update this post once they’re public.