Writing good firewall rules: least privilege, ordering, objects, documentation and clean-up
In short: Good firewall rules allow only what a specific business need requires: specific sources, destinations and services, with a named owner and reason. Order matters, so place specific rules above broad ones and watch for shadowed rules. Use named objects and groups, log important rules, review rules regularly using hit counts, and remove those no longer needed.
Why firewall policies decay
Most firewalls start tidy. Over years, urgent requests are opened with "any" to get things working, temporary rules become permanent, servers are retired but their rules stay, and nobody knows who asked for what. Large rule bases full of overly broad rules are one of the most common findings in security audits, and they make breaches easier and troubleshooting harder.
Principles for each rule
- Least privilege: specific source, specific destination, specific port or application. "Accounts team to payroll server on HTTPS", not "inside to DMZ any".
- Avoid "any" in more than one field. "Any source to the web server on 443" can be fine for a public website; "any to any on any" never is.
- Default deny: anything not explicitly allowed is blocked, with a logged deny rule at the end.
- Use applications and users where possible on next-generation firewalls (App-ID, user groups), not just ports.
- Owner, reason and expiry in the rule's comment or a ticket reference: "INC-4521, Finance, payroll export, review 2027-03".
Order and shadowing
Firewalls check rules from top to bottom and stop at the first match. A broad rule above a specific one shadows it: the specific rule can never be hit. Place specific rules first, group related rules into clear sections (for example by zone pair or application), and use the firewall's analysis tools to find shadowed and redundant rules.
Objects and groups
Define named objects for hosts, subnets and services (SRV-PAYROLL-01, NET-FINANCE-USERS, SVC-HTTPS) and use them in rules instead of raw addresses. When a server's IP changes, you update one object. Use a naming convention that everyone follows.
Logging
Log denied traffic and important allow rules, and send logs to a SIEM or log platform. Logging every high-volume allow rule can overload the firewall and storage, so be selective. Logs are the evidence that a rule is still used and the first place you look in an incident.
Reviews and clean-up
- Look at hit counts: rules with zero hits over 90 days are candidates for removal (be careful with yearly processes such as audits or disaster recovery).
- Recertify rules at least yearly with their owners: still needed? still this broad?
- Disable before deleting, so a rule can be restored quickly if something breaks.
- Tools such as AlgoSec, Tufin, FireMon and built-in vendor analysers help on large rule bases.
Change management
Every new rule should come from a request that states the business need, the exact flows and how long it is needed. A second person reviews it before it is applied. This slows nothing down once it is routine, and it prevents most dangerous "temporary" rules.
Real-world example: the 4,000-rule firewall
A company's main firewall had grown to more than 4,000 rules, and changes took days because nobody understood the policy. An analysis showed 38 percent of rules had no hits in a year, 600 were shadowed, and 90 used "any" as the service. Over three months, the team removed unused rules after owner checks, tightened the broadest ones, and introduced named objects and an approval process. The rule base fell to about 1,500 rules and changes became same-day.
Practice
What is a shadowed firewall rule?
What should every firewall rule record besides the traffic it allows?
Why disable a rule before deleting it?
Key takeaways
- Allow only specific sources, destinations and services for a real need.
- Order specific rules above broad ones and find shadowed rules.
- Use named objects, selective logging and a default deny.
- Review hit counts, recertify rules and remove what is no longer used.
Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.