Veljko Radan

Language: SvenskaEN

← All articles

Moving firewall rules without downtime

The firewall is the machine everything depends on. How I moved the whole rule set to a new format without the network going down even once.

Veljko Radan · · 4 min read

The firewall is the one machine on the network that everything else depends on. Get it wrong and you notice at once, and in the worst case you lock yourself out. Yet sometimes the rule set has to move. This is how I moved the entire rule set of my home firewall to a new format without the network going down even once.

Why move at all

OPNsense can store firewall rules in two ways: an older format and a newer one with a proper API. Rules in the older format can only be changed by clicking through the web interface. Rules in the new format can be read, changed and compared through the API. That means a change can be prepared, reviewed and repeated instead of clicked together in hope.

The move covered 17 filter rules and 4 NAT rules, among them the rule that forces all traffic from the home network through a VPN tunnel. That rule must not disappear for even a minute.

Moving the firewall rules in three steps 1 · Before2 · During the move3 · After Old rules17 filter + 4 NAT New ruleshits: all traffic Old ruleshits: 0 New rules0 old rules left backup comparison: 0 differences countersprove it→ remove
The move in three steps. For a while every rule existed twice, and the traffic counters decided when the old ones could go.

1. Back up before every step

Before every step, not just the first, the full configuration was downloaded and stored. If something went wrong, rolling back would mean restoring a known version, not trying to remember what it looked like.

2. New next to old, never instead of

The rules were exported and added as new rules in the new format. The old ones stayed. For a while every rule existed twice, with the new ones first. Had anything been missing from the new rules, traffic would have fallen through to the old ones instead of being blocked.

3. Compare field by field, by machine

A firewall rule is more than source and destination. It has protocol, ports, direction, gateway, logging and its place in the order. Every new rule was compared with the original field by field by a script, not by eye. The requirement was zero differences before anything else happened.

The comparison caught something a quick review would have missed: two rules the system presented as automatic turned out to be old manual rules. Without them, default traffic would have been blocked.

4. Let the traffic prove it

The firewall counts how much traffic each rule matches. After activation I watched the counters: the new rules took all the traffic and the old ones sat still at zero. Only then was it proven that the new rules did the job, not just that they existed.

5. Remove the old and check again

Once the counters looked right, the old rules were removed. Then everything was checked once more: that traffic leaves through the VPN tunnel, that the exceptions go straight out (streaming services that require a Swedish IP address, for example), that DNS works and that every server answers. The same method was then used for the NAT rules. No reboot was needed; the changes were loaded live.

Names that stay true

Along the way I renamed everything. The VPN tunnels were named after the server they pointed to, until the server changed and the name became wrong. Now they are named after their role, and the server goes in the description. Every rule got a description in the form What – From → To (via what). A name should still be true after the next change.

What made the difference

  • A backup before every step, not just the first.
  • The new is built next to the old, never instead of it.
  • Comparison by machine instead of by eye.
  • Traffic counters as proof that the change works.
  • Checking what actually matters afterwards: the tunnel, the exceptions, DNS and the servers.

The measure of a successful network change is that nobody notices it. Nobody noticed this one.