<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[pfsense-rule-order: script to keep firewall rules in the right order automatically]]></title><description><![CDATA[<p dir="auto">pfSense always adds new rules to the bottom of the list. Every time you add one and forget to drag it to the right position, your security policy silently breaks. On top of that, any package that touches config.xml (pfBlockerNG being the obvious one) can shuffle your rule order without warning — this has come up in multiple threads here with no built-in fix.</p>
<p dir="auto">I got tired of manually fixing it every time so I wrote a small Python script that enforces rule order automatically.</p>
<p dir="auto"><strong>How it works:</strong></p>
<p dir="auto">Add a numeric prefix to your rule descriptions in the GUI:</p>
<pre><code>01 | Zoom UDP
02 | Zoom TCP
03 | Block IoT from accessing internal LAN
04 | Allow LAN to Whitelisted Internal Services
</code></pre>
<p dir="auto">Run via cron every 5 minutes. Each run:</p>
<ol>
<li>Reads config.xml</li>
<li>On first run — assigns prefix numbers to all existing rules based on their current position</li>
<li>Sorts rules by prefix number per interface</li>
<li>If anything changed — backs up config.xml, writes the updated version, reloads the filter</li>
<li>If order is already correct — does nothing</li>
</ol>
<p dir="auto"><strong>What it never touches:</strong></p>
<ul>
<li>pfBlockerNG auto rules (identified by pfB_ prefix in the description)</li>
<li>Floating rules (identified by &lt;floating&gt;yes&lt;/floating&gt; in config.xml)</li>
<li>Tailscale rules (identified by interface = tailscale)</li>
</ul>
<p dir="auto">These exclusions cover my setup, but your setup may have other rules or packages that shouldn't be touched. If you run into something that needs to be excluded, open an issue on GitHub or reply here and I'll add it.</p>
<p dir="auto">Works on WAN, LAN, and OPT interfaces independently.</p>
<p dir="auto">Tested on pfSense CE 2.7.2. Requires Python 3.x (included in pfSense).</p>
<p dir="auto"><a href="https://github.com/ngfblog/pfsense-rule-order" target="_blank" rel="noopener noreferrer nofollow ugc">pfsense-rule-order</a></p>
]]></description><link>https://forum.netgate.com/topic/200766/pfsense-rule-order-script-to-keep-firewall-rules-in-the-right-order-automatically</link><generator>RSS for Node</generator><lastBuildDate>Sat, 13 Jun 2026 00:33:30 GMT</lastBuildDate><atom:link href="https://forum.netgate.com/topic/200766.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 03 Jun 2026 05:21:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Thu, 04 Jun 2026 07:10:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ngf">@<bdi>ngf</bdi></a></p>
<p dir="auto">A newer pfSense will also give you access to the latest version pfBlockerng.<br />
Your issue might auto solve itself.</p>
]]></description><link>https://forum.netgate.com/post/1243651</link><guid isPermaLink="true">https://forum.netgate.com/post/1243651</guid><dc:creator><![CDATA[Gertjan]]></dc:creator><pubDate>Thu, 04 Jun 2026 07:10:58 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 14:35:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tinfoilmatt">@<bdi>tinfoilmatt</bdi></a> same here, i had no idea that setting affected manual rules until now, good to know.</p>
<p dir="auto"><img src="https://forum.netgate.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f64f.png?v=717669fab53" class="not-responsive emoji emoji-android emoji--pray" style="height:23px;width:auto;vertical-align:middle" title=":pray:" alt="🙏" /> thanks for the kind words on <span style="color:#f90606">blocklist-manager</span>, glad it's useful!</p>
]]></description><link>https://forum.netgate.com/post/1243623</link><guid isPermaLink="true">https://forum.netgate.com/post/1243623</guid><dc:creator><![CDATA[ngf]]></dc:creator><pubDate>Wed, 03 Jun 2026 14:35:43 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 14:27:21 GMT]]></title><description><![CDATA[<p dir="auto">At one point, I would've spent a lot of time parsing that blue infoblock in my own mind. I'm certain there are good use cases for the non-default options. But it either never occured to me, or I had forgotten that those last two <em>do</em> affect non-pfBlockerNG rule ordering. Thanks for the refresher.</p>
<p dir="auto">By the way, I like what you're doing with your <a href="https://github.com/ngfblog/blocklist-manager" target="_blank" rel="noopener noreferrer nofollow ugc">blocklist-manager</a> tool.</p>
]]></description><link>https://forum.netgate.com/post/1243622</link><guid isPermaLink="true">https://forum.netgate.com/post/1243622</guid><dc:creator><![CDATA[tinfoilmatt]]></dc:creator><pubDate>Wed, 03 Jun 2026 14:27:21 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 14:18:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tinfoilmatt">@<bdi>tinfoilmatt</bdi></a> said in <a href="/post/1243620">pfsense-rule-order: script to keep firewall rules in the right order automatically</a>:</p>
<blockquote>
<p dir="auto">Additionally (and with the default setting there)—if for whatever reason you need a pass rule above pfBlockerNG's auto-added block rules, then the way to do that would be by way of the "Permit" feed group action options (i.e., actions "Permit Inbound" for WAN interface/s, "Permit Outbound" for LAN interface/s, or "Permit Both"). This would be the cleanest and most automated way to "whitelist" any pfBlockerNG false positives.</p>
</blockquote>
<p dir="auto">Thanks, I'll check with the default setting.<br />
If that solves the reordering problem, the script is still useful as a general safety net for rule ordering, but the main reason here was clearly misconfiguration on my part.</p>
]]></description><link>https://forum.netgate.com/post/1243621</link><guid isPermaLink="true">https://forum.netgate.com/post/1243621</guid><dc:creator><![CDATA[ngf]]></dc:creator><pubDate>Wed, 03 Jun 2026 14:18:59 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 14:15:44 GMT]]></title><description><![CDATA[<p dir="auto">Additionally (and with the default setting there)—if for whatever reason you <em>need</em> a pass rule <em>above</em> pfBlockerNG's auto-added block rules, then the way to do that would be by way of the "Permit" feed group action options (i.e., actions "<code>Permit Inbound</code>" for WAN interface/s, "<code>Permit Outbound</code>" for LAN interface/s, or "<code>Permit Both</code>"). This would be the cleanest and most automated way to "whitelist" any pfBlockerNG false positives.</p>
]]></description><link>https://forum.netgate.com/post/1243620</link><guid isPermaLink="true">https://forum.netgate.com/post/1243620</guid><dc:creator><![CDATA[tinfoilmatt]]></dc:creator><pubDate>Wed, 03 Jun 2026 14:15:44 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 14:06:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tinfoilmatt">@<bdi>tinfoilmatt</bdi></a> I was not aware that this setting also affects manual rule ordering.<br />
i will change back to the default and disable the script temporarily to see if that alone solves the problem.<br />
thank you very much.</p>
]]></description><link>https://forum.netgate.com/post/1243619</link><guid isPermaLink="true">https://forum.netgate.com/post/1243619</guid><dc:creator><![CDATA[ngf]]></dc:creator><pubDate>Wed, 03 Jun 2026 14:06:33 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 13:56:45 GMT]]></title><description><![CDATA[<p dir="auto">Interesting. So those last two settings in the drop-down <em>can</em> and do affect 'manual rule' ordering.</p>
<p dir="auto">So then why not use the default setting which leaves "All other rules" unaffected by pfBlockerNG?</p>
]]></description><link>https://forum.netgate.com/post/1243618</link><guid isPermaLink="true">https://forum.netgate.com/post/1243618</guid><dc:creator><![CDATA[tinfoilmatt]]></dc:creator><pubDate>Wed, 03 Jun 2026 13:56:45 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 13:54:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tinfoilmatt">@<bdi>tinfoilmatt</bdi></a> said in <a href="/post/1243615">pfsense-rule-order: script to keep firewall rules in the right order automatically</a>:</p>
<blockquote>
<p dir="auto">Firewall 'Auto' Rule Order</p>
</blockquote>
<p dir="auto"><img src="/assets/uploads/files/1780494869465-aa4b408f-ea7b-4cc8-a7c8-c0cffee10854-image.png" alt="aa4b408f-ea7b-4cc8-a7c8-c0cffee10854-image.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.netgate.com/post/1243617</link><guid isPermaLink="true">https://forum.netgate.com/post/1243617</guid><dc:creator><![CDATA[ngf]]></dc:creator><pubDate>Wed, 03 Jun 2026 13:54:33 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 13:49:48 GMT]]></title><description><![CDATA[<blockquote>
<p dir="auto">my issue was specifically manual rules getting reordered relative to each other</p>
</blockquote>
<p dir="auto">This wouldn't be caused by pfBlockerNG's cron job. The order of non-pfBlockerNG auto-added rules (i.e., 'manual rules') could only be changed manually.</p>
<p dir="auto">What do you have for that package setting—"<code>Firewall &gt; pfBlockerNG &gt; IP &gt; IP Interface/Rules Configuration &gt; Firewall 'Auto' Rule Order</code>"?</p>
]]></description><link>https://forum.netgate.com/post/1243615</link><guid isPermaLink="true">https://forum.netgate.com/post/1243615</guid><dc:creator><![CDATA[tinfoilmatt]]></dc:creator><pubDate>Wed, 03 Jun 2026 13:49:48 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 13:43:41 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tinfoilmatt">@<bdi>tinfoilmatt</bdi></a> said in <a href="/post/1243613">pfsense-rule-order: script to keep firewall rules in the right order automatically</a>:</p>
<blockquote>
<p dir="auto">There are package settings which address auto-added rule ordering. Do those not cover your situation?</p>
</blockquote>
<p dir="auto">I looked at the pfBlockerNG rule order settings but they control where pfBlockerNG places its own auto rules relative to manual ones, not the order of manual rules themselves.<br />
my issue was specifically manual rules getting reordered relative to each other, so those settings didn't help in my case.</p>
]]></description><link>https://forum.netgate.com/post/1243614</link><guid isPermaLink="true">https://forum.netgate.com/post/1243614</guid><dc:creator><![CDATA[ngf]]></dc:creator><pubDate>Wed, 03 Jun 2026 13:43:41 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 13:40:06 GMT]]></title><description><![CDATA[<p dir="auto">There are package settings which address auto-added rule ordering. Do those not cover your situation?</p>
]]></description><link>https://forum.netgate.com/post/1243613</link><guid isPermaLink="true">https://forum.netgate.com/post/1243613</guid><dc:creator><![CDATA[tinfoilmatt]]></dc:creator><pubDate>Wed, 03 Jun 2026 13:40:06 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 13:37:46 GMT]]></title><description><![CDATA[<p dir="auto">The actual issue I ran into was pfBlockerNG's cron job moving my "Block IoT" rule below some Allow rules every hour.<br />
it was already in the right place, pfBlockerNG just kept pushing it down.<br />
That's what the script is for.</p>
<p dir="auto">Regarding my version, yes, i know. i'm in the process of replacing the pfsense box.</p>
]]></description><link>https://forum.netgate.com/post/1243612</link><guid isPermaLink="true">https://forum.netgate.com/post/1243612</guid><dc:creator><![CDATA[ngf]]></dc:creator><pubDate>Wed, 03 Jun 2026 13:37:46 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 13:26:53 GMT]]></title><description><![CDATA[<p dir="auto">Whatever it's catching, I agree, is worth filtering.</p>
]]></description><link>https://forum.netgate.com/post/1243610</link><guid isPermaLink="true">https://forum.netgate.com/post/1243610</guid><dc:creator><![CDATA[tinfoilmatt]]></dc:creator><pubDate>Wed, 03 Jun 2026 13:26:53 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 13:14:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tinfoilmatt">@<bdi>tinfoilmatt</bdi></a> said in <a href="/post/1243608">pfsense-rule-order: script to keep firewall rules in the right order automatically</a>:</p>
<blockquote>
<p dir="auto">Ditto for any LAN interfaces ..</p>
</blockquote>
<p dir="auto">Initially, I listed that one as well. But I spotted something strange, so I withdrew it.<br />
So here it is :</p>
<p dir="auto"><img src="/assets/uploads/files/1780492266733-c67f922f-1fd3-4ce6-871d-0481dac0dbae-image.png" alt="c67f922f-1fd3-4ce6-871d-0481dac0dbae-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">After years of rule building ( I was in the past also a fan of "every packet needs its own rule", but then I found the cure and live was good again) I found rule number 3 and 4.<br />
I added a final block all rule, but this one could never match, as the perfect rules 3 and 4 exist.<br />
Still : rule 5 matches ones in a while 'something'. After a 'everything' there shouldn't be a 'something'.<br />
Right ?</p>
]]></description><link>https://forum.netgate.com/post/1243609</link><guid isPermaLink="true">https://forum.netgate.com/post/1243609</guid><dc:creator><![CDATA[Gertjan]]></dc:creator><pubDate>Wed, 03 Jun 2026 13:14:48 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 13:07:45 GMT]]></title><description><![CDATA[<p dir="auto">Ditto for any LAN interfaces on which outbound filtering is performed. Plus it adds an easy logging 'toggle' for troubleshooting.</p>
]]></description><link>https://forum.netgate.com/post/1243608</link><guid isPermaLink="true">https://forum.netgate.com/post/1243608</guid><dc:creator><![CDATA[tinfoilmatt]]></dc:creator><pubDate>Wed, 03 Jun 2026 13:07:45 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 12:59:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/gertjan">@<bdi>Gertjan</bdi></a> that is actually a good policy.. And a very valid reason to have extra block rule there at the end vs just the hidden last rule. Nice..</p>
]]></description><link>https://forum.netgate.com/post/1243607</link><guid isPermaLink="true">https://forum.netgate.com/post/1243607</guid><dc:creator><![CDATA[johnpoz]]></dc:creator><pubDate>Wed, 03 Jun 2026 12:59:46 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 12:50:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ngf">@<bdi>ngf</bdi></a> said in <a href="/post/1243597">pfsense-rule-order: script to keep firewall rules in the right order automatically</a>:</p>
<blockquote>
<p dir="auto">pfSense always adds new rules to the bottom of the list. Every time you add one and forget to drag it to the right position, your security policy silently breaks.</p>
</blockquote>
<p dir="auto">Good policy, if applied, can't be broken (it wouldn't be good to start with).<br />
Let me explain with my 'policy' WAN rules :</p>
<p dir="auto"><img src="/assets/uploads/files/1780490300325-4ee22dfd-02dc-4932-82f8-672f7f61f6b3-image.png" alt="4ee22dfd-02dc-4932-82f8-672f7f61f6b3-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">You see the last two rules ? These are the final 'block all' rules, separated for IPv6 and IPv4.<br />
And yes, these two rules are the same as the 'hidden' default behavior : block all.</p>
<p dir="auto">So, if you wanted to add a new WAN pass rule, it would be inserted at the bottom, being completely inoffensive. As soon as you see it, you have to drag it to to correct place, and save. Forgetting to do so won't get you fired. Policies won't get broken <img src="https://forum.netgate.com/assets/plugins/nodebb-plugin-emoji/emoji/android/1f60a.png?v=717669fab53" class="not-responsive emoji emoji-android emoji--blush" style="height:23px;width:auto;vertical-align:middle" title=":blush:" alt="😊" /></p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ngf">@<bdi>ngf</bdi></a> said in <a href="/post/1243597">pfsense-rule-order: script to keep firewall rules in the right order automatically</a>:</p>
<blockquote>
<p dir="auto">Tested on pfSense CE 2.7.2.</p>
</blockquote>
<p dir="auto">Now you are breaking one of the most important security rules. 2.7.2 was good, and now 'ancient'.</p>
]]></description><link>https://forum.netgate.com/post/1243606</link><guid isPermaLink="true">https://forum.netgate.com/post/1243606</guid><dc:creator><![CDATA[Gertjan]]></dc:creator><pubDate>Wed, 03 Jun 2026 12:50:49 GMT</pubDate></item><item><title><![CDATA[Reply to pfsense-rule-order: script to keep firewall rules in the right order automatically on Wed, 03 Jun 2026 11:47:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ngf">@<bdi>ngf</bdi></a> said in <a href="/post/1243597">pfsense-rule-order: script to keep firewall rules in the right order automatically</a>:</p>
<blockquote>
<p dir="auto">pfSense always adds new rules to the bottom of the list</p>
</blockquote>
<p dir="auto">not it doesn't</p>
<p dir="auto"><img src="/assets/uploads/files/1780487264525-rule.jpg" alt="rule.jpg" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.netgate.com/post/1243604</link><guid isPermaLink="true">https://forum.netgate.com/post/1243604</guid><dc:creator><![CDATA[johnpoz]]></dc:creator><pubDate>Wed, 03 Jun 2026 11:47:46 GMT</pubDate></item></channel></rss>