---
title: "Configuring Firewall Rules | FiveStudy"
description: "How to write firewall rules from requirements, order them so specific rules come before broad ones, and test sample traffic before going live."
url: https://fivestudy.com/guides/ap-cybersecurity-3-4-d-configuring-firewall-rules
---

[AP Cybersecurity](https://fivestudy.com/ap-cybersecurity) · Study guide

# Configuring Firewall Rules

[Figure: FiveStudy]

FiveStudy

AP® Cybersecurity · Unit 3 · Network Security, Firewalls & Detection

AP® Cybersecurity · Unit 3 · Network Security, Firewalls & Detection

# Configuring Firewall Rules

How to turn a list of requirements into firewall rules, put them in the right order, and test what they allow.

1. From requirements to rules 2. Writing a rule 3. Ordering rules 4. Testing the rule set 5. Worked examples 6. Common mistakes

## 1 From requirements to rules

A firewall is configured from **requirements**: statements of what type of traffic, from which sources or to which destinations, should be allowed or denied. For example:

- “Anyone on the internet may load our website over HTTPS.”
- “Only the IT admin subnet may log in to the web server remotely.”
- “Block everything from a range of addresses that attacked us last week.”
- “Nothing else gets in.”

Each requirement becomes one or more rules. Rules can allow or deny inbound or outbound traffic based on source or destination port or IP address, service, protocol, or application.

## 2 Writing a rule

Rules follow a consistent pattern: *action, direction, protocol, port, source*. Two examples:

| Rule | What it does |
| --- | --- |
| `ALLOW inbound TCP port 22 from ALL` | Allows all inbound TCP traffic with destination port 22, the port for SSH (secure remote login), from any address |
| `DENY inbound TCP port 80 from 192.168.1.0/24` | Denies inbound TCP traffic to port 80 (unencrypted web) from addresses `192.168.1.0` to `192.168.1.255` |

Translate requirements carefully: “only the admin subnet” means the *source* must be that subnet's range, not `ALL`; “nothing else” means a final deny rule.

## 3 Ordering rules

Rules are applied in order, and the first matching rule decides. So changing the order of a set of rules can change which traffic is allowed or denied. When ordering, think about **precedence**: which rule should win when two could match the same packet?

**Figure 1.** Changing the order of rules can change what is allowed. Specific rules go before the broad rules that would otherwise catch the same traffic.

A reliable pattern:

1. Specific exceptions first (allow the admin subnet's SSH; deny a known-bad range).
2. Then broader allows (allow HTTPS from everyone).
3. Finally, a deny-all rule that catches everything not allowed above.

## 4 Testing the rule set

Before going live, walk sample traffic through the rules and confirm each result matches the requirements. Here is a rule set for a web server segment:

Web server segment rules

```
Rule 1: ALLOW inbound TCP port 22 from 10.10.9.0/24
Rule 2: DENY inbound TCP ALL from 198.51.100.0/24
Rule 3: ALLOW inbound TCP port 443 from ALL
Rule 4: DENY inbound ALL ALL from ALL
```

| Test traffic | Packet | Result | Matches requirement? |
| --- | --- | --- | --- |
| Visitor loads the site | inbound TCP port 443 from `203.0.113.40` | ALLOW (Rule 3) | Yes |
| Admin logs in from 10.10.9.12 | inbound TCP port 22 from `10.10.9.12` | ALLOW (Rule 1) | Yes |
| Login attempt from the internet | inbound TCP port 22 from `203.0.113.40` | DENY (Rule 4) | Yes |
| Blocked range visits the site | inbound TCP port 443 from `198.51.100.3` | DENY (Rule 2) | Yes |
| Unencrypted web request (port 80) | inbound TCP port 80 from `203.0.113.40` | DENY (Rule 4) | Yes |

The key idea

Write one rule per requirement, put specific rules before broad ones and a deny-all last, then test sample traffic against the requirements before trusting the configuration.

## 5 Worked examples

Worked Example 1 Requirements to rules

### The web server segment

Requirements: (1) anyone may reach the website over HTTPS (TCP 443); (2) only the admin subnet `10.10.9.0/24` may use SSH (TCP 22); (3) block all traffic from `198.51.100.0/24`, including website visits; (4) deny everything else. Write the rules in order.

1. 1

   Requirement 2 is a specific allow: `ALLOW inbound TCP port 22 from 10.10.9.0/24`.

2. 2

   Requirement 3 must beat the HTTPS allow, so it goes before it: `DENY inbound TCP ALL from 198.51.100.0/24`.

3. 3

   Requirement 1: `ALLOW inbound TCP port 443 from ALL`.

4. 4

   Requirement 4 last: `DENY inbound ALL ALL from ALL`.

**Answer:** The four rules in the box above, in that order. The test table confirms each requirement.

Worked Example 2 Predict the outcome

### Two rules, two orders

Rules: `Rule 1: ALLOW inbound TCP port 22 from ALL`; `Rule 2: DENY inbound TCP ALL from ALL`. What happens to (a) an SSH packet, (b) a web request on port 80? Then reverse the rules.

1. 1

   (a) SSH on port 22 matches Rule 1: allowed.

2. 2

   (b) Port 80 does not match Rule 1; it matches Rule 2: denied.

3. 3

   Reversed: the deny-all TCP rule comes first and matches every TCP packet, including SSH. Both are denied, and the SSH rule is never reached.

**Answer:** In order: SSH allowed, everything else denied. Reversed: all inbound TCP denied, including SSH.

Worked Example 3 Debug the order

### Why is the blocked range getting in?

An administrator writes the rules in this order: allow TCP 443 from ALL; deny TCP from `198.51.100.0/24`; allow TCP 22 from `10.10.9.0/24`; deny all. Logs show `198.51.100.3` still loading the website. Why, and how is it fixed?

1. 1

   A request from `198.51.100.3` to port 443 matches the first rule (allow 443 from ALL).

2. 2

   First match wins, so the deny rule for that range is never reached for website traffic.

3. 3

   Fix: move the deny for `198.51.100.0/24` above the HTTPS allow.

**Answer:** The broad allow is above the specific deny. Reordering fixes it.

Worked Example 4 Outbound rules

### Stopping data leaving

Requirement: computers on the records segment must not send data to the internet, except to the backup service at `203.0.113.50` on TCP 443. Which direction are these rules, and in what order?

1. 1

   These control traffic leaving the segment: outbound rules. For outbound traffic, the address that matters is the destination.

2. 2

   First, the specific exception: allow outbound TCP 443 to `203.0.113.50`.

3. 3

   Then deny all other outbound traffic to the internet.

**Answer:** Outbound rules: allow the backup destination first, then deny everything else outbound.

## 6 Common mistakes

Common Mistake 1 · Putting the deny-all rule first

A deny-all at the top blocks everything, because it matches every packet before any allow rule is reached.

Common Mistake 2 · Writing ALL when the requirement names a source

“Only the admin subnet may log in” needs the admin subnet's range as the source. `from ALL` opens SSH to the whole internet.

Common Mistake 3 · Forgetting outbound traffic

Requirements often limit what may leave a segment too. Outbound rules stop data theft and stop infected machines contacting attackers.

Common Mistake 4 · Skipping the test

Walk sample packets through the rules. A rule set can look right and still let through the very traffic a requirement forbids.

Explain a configuration like this

“Rule 2, the deny for 198.51.100.0/24, must come before Rule 3, which allows HTTPS from all addresses. Otherwise a website request from that range would match the HTTPS allow first and be permitted, because the firewall applies the first matching rule.”

Quote the rules, explain what each matches, and use first-match order to justify the arrangement.

FiveStudy AP® Cybersecurity · Configuring Firewall Rules
