Back

How to write firewall rules that hold up

Buying a firewall takes an afternoon. Configuring one correctly is work that continues for as long as the network exists. In most of the business networks we are asked to look at, the hardware is adequate and the licence is current, but the rule base has quietly grown into something nobody fully understands any more: permissions whose author is unknown, ports still open to servers that were decommissioned years ago, and a deny-everything rule sitting at the bottom of the list that never actually fires because a broad allow rule above it catches the traffic first. This article covers what a firewall rule is made of, why the order of the list matters more than the contents of any single line, and how to keep a rule base readable over time.

Before you write a rule, write the sentence

Every firewall rule is the technical form of a plain sentence. If you can say “the finance workstations may reach the database port on the accounting server and nothing else,” you can write that rule correctly. If you cannot say it in a sentence, the rule you write will almost certainly be broader than you intended, because vagueness in the requirement turns into a wildcard in the configuration.

So before opening the console, write down three lists:

  • Assets: which servers, applications and device groups are being protected. Record them as address ranges rather than hostnames. Names change when machines are replaced; the segment plan survives.
  • Parties: office staff, remote staff, guests, contractors, cameras and other IoT devices, and the administrators who legitimately need the management interfaces.
  • Directions: outbound, inbound, and the one almost everybody skips, which is internal to internal.

That third direction is where most of the real exposure sits. In a great many organisations the firewall guards only the internet boundary while the entire internal network runs as one flat space. In that design, a single compromised laptop can reach every server at the network level, and no boundary rule helps. Filtering internal traffic requires the network to be segmented first, which we covered in detail in our article on network security groundwork and VLAN segmentation.

The default should be deny, not allow

There are two ways to build a rule base. In the first, everything is permitted and you close off what you consider dangerous. In the second, everything is blocked and you open only what is required. The first is easier in the short term and indefensible in the long term, because it asks you to enumerate every threat in advance, which nobody can do.

The correct structure is the second. A rule that denies all traffic sits at the end of the list, and every permission is written explicitly above it. The practical consequence is that a port you forgot about stays closed rather than staying open. It changes the outcome of an ordinary configuration mistake from “anyone can reach this” to “someone cannot reach this and will tell you within the hour.” The second failure mode is the one you want.

The anatomy of a rule

Whatever the vendor or the interface, a rule answers the same questions:

  1. Source: who initiates the traffic. A single address, a group, or an entire segment.
  2. Destination: what the traffic is trying to reach.
  3. Service: the protocol and port. Seeing the protocol and port number written out is safer for whoever reads the rule later than a pre-built service object whose definition they would have to go and look up.
  4. Action: allow, reject, or drop. Reject and drop are not the same behaviour: reject returns a response to the sender, drop returns nothing. Internally, an explicit reject makes troubleshooting far quicker; on the internet-facing side, a silent drop gives a scanner less to work with.
  5. Direction and interface: which leg the rule applies to. A perfectly written rule on the wrong interface does nothing at all.

Three further fields deserve to be filled in every time: a comment recording why the rule exists, who requested it and when; the logging setting; and an expiry date where one applies. Temporary access granted to a contractor becomes permanent access the moment the end date lives only in somebody’s memory.

Writing rules against address groups rather than individual hosts is both shorter and more durable: when a new finance workstation arrives you add it to the group and leave the rule base untouched. The trade-off is that group membership needs reviewing too, since a group nobody audits will silently widen a narrow permission. Name groups for the access they represent rather than for the department that happened to request them, and they will still make sense in three years.

How to plan a firewall ruleset before you touch the device

Most rule lists that become unmanageable were never designed. They accumulated: someone needed access on a Tuesday, a rule went in at the top, and nobody wrote down why. Planning the ruleset on paper first is what keeps that from happening, and it takes four steps.

One: inventory what you actually have. List the servers and the service each one really serves, the user groups, the branch sites, the remote access pool, and the devices nobody thinks of as computers — printers, cameras, card readers, the NVR. You cannot write a rule for a service you have not named.

Two: group everything into zones. A zone is a set of addresses you are willing to treat as one trust level: office clients, servers, management, guests, cameras and IoT, remote access, branches, internet. Zones are what let you write ten rules instead of two hundred, and they come from the network design itself — this is where VLAN segmentation and the rule list stop being two separate jobs.

Three: write the traffic matrix. Put the zones down the left as sources and across the top as destinations, and in each cell write the services that are allowed and nothing else. The matrix is the design. It is also the document that survives staff turnover, and the thing you hand an auditor when they ask why a port is open.

Four: agree a naming convention and a change record. A rule called ALLOW-Office-to-ERP-SQL explains itself three years later; a rule called rule_17 does not. Every rule should carry who asked for it, when, and when it should be reviewed again.

Here is what a small-office matrix looks like once it is turned into an ordered rule list — a worked example, not a template to paste in:

  1. Management: Admin zone to network devices, SSH and HTTPS only, allow, logged.
  2. Guest isolation: Guest zone to every internal range, deny, logged — placed above the guest internet rule, because order decides which one wins.
  3. Guest internet: Guest zone to internet, HTTP, HTTPS and DNS to your resolvers, allow.
  4. Cameras and IoT: IoT zone to the recorder only, on the recorder’s port, allow; IoT zone to internet and to all internal ranges, deny, logged.
  5. Office to servers: Office zone to server zone, named application ports only — not “any” — allow.
  6. Office to internet: Office zone to internet, allow, with whatever filtering policy you run.
  7. Remote access: the corporate VPN pool to the server zone, the same named services as the office and no more.
  8. Branches: branch zone to server zone, named services, allow.
  9. Catch-all: any to any, deny, logged. This is the rule that tells you what you forgot.

Nine rules, each one explainable in a sentence. If your list is twenty times that length and nobody can explain a given line, the fix is not another rule — it is going back to the matrix.

Order decides everything

Firewalls read the rule base from top to bottom and apply the first rule that matches, ignoring everything below it. This single behaviour is the source of the most common mistake in rule writing: a broad allow rule near the top renders every specific restriction beneath it inert. The restriction is visible in the console, it appears in the audit export, and it never once takes effect.

A workable ordering is: explicit denies first, then narrow and specific allows, then broader allows, then the deny-all at the bottom. The instinct to append each new rule to the end of the list is usually wrong. A rule’s position should follow from how broad it is, not from when it was added.

The only reliable way to know whether a rule is doing anything is to read its hit counter. Most products keep one per rule. An allow rule that has stayed at zero for months is telling you one of two things: either nobody needs that access any more, or a rule above it is already catching the traffic. Both are worth investigating, and both end with the list getting shorter.

Testing before applying is possible and worth the minute it takes. Most platforms include a rule lookup or packet tracer: enter a source, destination and port and it tells you which line would match. That is considerably cheaper than discovering the answer in production. If you are working on a device you reach remotely, account for the risk of cutting off your own access while reordering, and use the confirmed-commit mechanism that reverts on timeout if the platform offers one.

Scoping remote access and branch traffic

A remote user arriving through the tunnel should not thereby be on the whole internal network. The right structure treats the tunnel as its own source segment and states explicitly which servers and which ports that segment may reach. Someone who needs the accounting application has no business reaching server management interfaces, and the only thing standing between those two states is a rule somebody has to write.

Branch connectivity follows the same logic. Joining two sites should not produce one large flat network; you write only the resources each site genuinely needs from the other. We have covered the protocol choice behind this in our enterprise VPN solutions pages and in our WireGuard and IPsec comparison.

One distinction worth stating plainly: VPN in this article means corporate use only, meaning staff reaching company resources remotely and branches connecting to each other. We do not provide personal VPN services for bypassing geographic restrictions or for anonymous browsing.

Logging, change records and the regulatory side

Logging every rule produces noise nobody reads; logging none of them makes post-incident investigation impossible. A reasonable middle position is to log deny rules and all traffic arriving at internet-facing services, skip the high-volume routine internal traffic, and log access to critical servers without exception.

Rule changes need a record of their own. If nobody can answer who added a rule, when, and on whose request, then months later nobody will be willing to remove it, and the list only ever grows. Keeping the configuration under version control and taking a backup before every change will save you more work than everything else in this article combined.

Retention periods and the handling of logs that contain personal data carry their own legal requirements, and in Turkey that means the KVKK framework. We build and operate the technical side; deciding retention periods and assessing compliance is work for your legal counsel. Neo1 Technology does not provide legal or financial advisory services.

Keeping the list clean, and where to start

Rule bases grow on their own and never shrink on their own. Without a scheduled review, every list eventually becomes unreadable. A review asks:

  • Which rules have hit counters that never move, and why?
  • Are there permissions left over from decommissioned servers or closed projects?
  • Is there access that was clearly opened temporarily and is still in place?
  • Are there overlapping lines that could collapse into one rule?
  • Does any rule expose a management interface directly to the internet? There should not be one.
  • Which rules have an empty comment field?

The last question looks like housekeeping but produces the most value. A rule with no explanation is a rule that stays forever, because removing something whose purpose is unknown feels riskier than leaving it.

You do not need to start from a blank slate on an existing network. In most organisations these steps produce visible improvement quickly:

  1. Back up the current rule base and export it together with the hit counters.
  2. Confirm that the bottom of the list really does deny everything.
  3. Find and close any rule exposing a management interface, whether on a server, the firewall itself, a camera recorder or a network device, to the internet.
  4. Write down where the remote-access segment can currently reach inside the network, then narrow it.
  5. Trace the owner of every uncommented rule; where no owner can be found, watch it with logging enabled and remove it once you have confirmed it is unused.
  6. Put the review in the calendar. Work that happens when someone remembers is work that does not happen.

If you would like us to read through your current rule base with you, we offer a free initial assessment as part of our network security services: we review the existing configuration, the segment plan and the remote-access rules, and send you a written note on what to address first and in what order. For the wider picture, our network infrastructure services page covers the rest of the network side. To talk it through, reach us via our contact page.

Neo1 Technology
Neo1 Technology
https://neo1.com.tr