Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Search
    • Register
    • Login
    Introducing Netgate Nexus: Multi-Instance Management at Your Fingertips.

    Rules order randomly changes

    Scheduled Pinned Locked Moved Plus 25.07 Develoment Snapshots (Retired)
    33 Posts 7 Posters 11.2k Views 9 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      marcosm Netgate @w0w
      last edited by

      @w0w Thank you. Try with this patch:

      diff --git a/src/etc/inc/pfsense-utils.inc b/src/etc/inc/pfsense-utils.inc
      index 5095c9ff0f..23cdbdf295 100644
      --- a/src/etc/inc/pfsense-utils.inc
      +++ b/src/etc/inc/pfsense-utils.inc
      @@ -3088,18 +3088,33 @@ function filter_rules_sort() {
       	config_set_path('filter/rule', $rules);
       }
       function filter_rules_compare($a, $b) {
      -	if ((isset($a['floating']) && isset($b['floating'])) ||
      -	    (isset($b['ethernet']) && isset($b['ethernet']))) {
      -		return $a['seq'] - $b['seq'];
      -	} else if (isset($a['floating']) || isset($a['ethernet'])) {
      -		return -1;
      -	} else if (isset($b['floating']) || isset($b['ethernet'])) {
      +	if (isset($a['ethernet'])) {
      +		// Ethernet rules always come first.
      +		if (!isset($b['ethernet'])) {
      +			return -1;
      +		}
      +	} elseif (isset($a['floating'])) {
      +		// Floating rules are placed after Ethernet rules and before Interface rules.
      +		if (isset($b['ethernet'])) {
      +			return 1;
      +		} elseif (!isset($b['floating'])) {
      +			return -1;
      +		}
      +	} elseif (isset($b['ethernet']) || isset($b['floating'])) {
      +		// Interface rules are placed after Ethernet and Floating rules.
       		return 1;
      -	} else if ($a['interface'] == $b['interface']) {
      -		return $a['seq'] - $b['seq'];
      -	} else {
      +	} elseif ($a['interface'] != $b['interface']) {
      +		// Interface rules for the same interface are grouped together.
       		return compare_interface_friendly_names($a['interface'], $b['interface']);
       	}
      +
      +	// Use the sequence number as a last resort.
      +	if (isset($a['seq']) && isset($b['seq'])) {
      +		return ($a['seq'] <=> $b['seq']);
      +	}
      +
      +	// Nothing to compare.
      +	return 0;
       }
       
       function generate_ipv6_from_mac($mac) {
      
      

      If testing on 24.11, apply this one after first applying the latest recommended System patches. If testing on 25.03-BETA, first apply c181ebe180017116626da28f30407a1da3cba061 and the previous one, then this one.

      w0wW 1 Reply Last reply
      Reply Quote 2
      • w0wW
        w0w @marcosm
        last edited by w0w

        @marcosm said in Rules order randomly changes:

        At first glance, everything seems to be working, but we won't rush. I'll test it for some more time.

        A 1 Reply Last reply
        Reply Quote 1
        • patient0P patient0 referenced this topic on
        • A
          aGeekhere @w0w
          last edited by

          This is still happening on pfsense 2.8.1-RELEASE rules can get rearranged after saving.

          Never Fear, A Geek is Here!

          patient0P 1 Reply Last reply
          Reply Quote 0
          • patient0P
            patient0 @aGeekhere
            last edited by

            @aGeekhere the mentioned patches should definitely be in 2.8.1. Please provide more details and how to reproduce it, if possible.

            A 1 Reply Last reply
            Reply Quote 0
            • A
              aGeekhere @patient0
              last edited by

              @patient0 Here are the things that i did to cause it,

              1. Use separators
              2. Move rules around and save
              3. Using pfBlockerNG rules, moving them to the bottom

              It could be working then i reboot and it can switch around

              Never Fear, A Geek is Here!

              patient0P 1 Reply Last reply
              Reply Quote 0
              • patient0P
                patient0 @aGeekhere
                last edited by

                @aGeekhere what have you set in pfBlockerNG / IP > Firewall 'Auto' Rule Order ?

                A 1 Reply Last reply
                Reply Quote 0
                • A
                  aGeekhere @patient0
                  last edited by

                  @patient0
                  00fba102-bcc1-4dcd-8c48-db8339cece79-image.png

                  Never Fear, A Geek is Here!

                  patient0P 1 Reply Last reply
                  Reply Quote 0
                  • patient0P
                    patient0 @aGeekhere
                    last edited by

                    @aGeekhere I was hoping to get to a "give a man a fish, teach a man to fish" situation, but I failed.

                    If you press the blue 'i' thingy it will explain what that setting does.

                    The setting you have, means pfBlocker rules at the top, all other rules after that. And that's why they are moved back to the top.

                    You read:
                    https://docs.netgate.com/pfsense/en/latest/packages/pfblocker.html#faq

                    "pfBlocker always moves its rules to the top, how can I stop this?:"

                    keyserK 1 Reply Last reply
                    Reply Quote 0
                    • keyserK
                      keyser Rebel Alliance @patient0
                      last edited by

                      @patient0 said in Rules order randomly changes:

                      @aGeekhere I was hoping to get to a "give a man a fish, teach a man to fish" situation, but I failed.

                      If you press the blue 'i' thingy it will explain what that setting does.

                      The setting you have, means pfBlocker rules at the top, all other rules after that. And that's why they are moved back to the top.

                      You read:
                      https://docs.netgate.com/pfsense/en/latest/packages/pfblocker.html#faq

                      "pfBlocker always moves its rules to the top, how can I stop this?:"

                      I never liked the fact pfBlockerNG does rules injection/sorting, so I deliberately do not use it. The only way I have found out to “avoid it” is by not letting it create any rules at all:

                      In the “inbound/outbound firewall rules” just above the sorting selector, make sure you have no interfaces selected.
                      In the auto rules sorting selector there is NO “do not mess with my rules”, so I had to resort to not let it create any rules.

                      Afterwards make sure you set all your IP blocking lists to generate “aliases” instead. Essentially that will generate aliases in the FIREWALL -> ALIASES -> URLs section that you can then use in your created firewall rules as needed - and placed where you like.

                      MUCH MUCH better way of doing firewalling even though it does take a little longer to create the basic block/allow countries this way.

                      Love the no fuss of using the official appliances :-)

                      A 1 Reply Last reply
                      Reply Quote 0
                      • A
                        aGeekhere @keyser
                        last edited by

                        @keyser Thank you i now understand what is happening

                        Never Fear, A Geek is Here!

                        1 Reply Last reply
                        Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • First post
                          Last post
                        Copyright 2026 Rubicon Communications LLC (Netgate). All rights reserved.
                        Privacy Policy · Cookie Policy