AP® Cybersecurity

Firewalls | AP® Cybersecurity Topic 3.4

Learn how packet filtering, stateful inspection, proxy, cloud, next-generation, and web application firewalls protect networks, then test your knowledge.

AP® Cybersecurity · Unit 3: Securing Networks · Topic 3.4

Protecting Networks: Firewalls

A firewall is a security control that monitors and controls network traffic between systems or networks with different security requirements. It compares traffic with an approved policy, allows legitimate communication, blocks prohibited communication, and records events that may need review.

What is a firewall, and how does it work?

A firewall sits at a policy enforcement point: a boundary between the internet and a home network, between school segments, between a cloud application and its database, or directly on a laptop. It inspects selected characteristics of network communication and compares them with an ordered ruleset.

Depending on its type, a firewall may inspect source and destination IP addresses, ports, protocols, direction, connection state, user or device identity, application behavior, URLs, headers, or other content. The result may be allow, deny, reject, log, alert, or route through another security service.

  1. Traffic arrivesA packet or connection reaches the enforcement point.
  2. Context is inspectedThe firewall examines the fields and state its design supports.
  3. Policy is matchedThe ruleset determines the applicable action.
  4. Action is recordedThe firewall allows or blocks and may log or alert.
Inbound traffic

Entering a host, network, zone, or application

Inbound policy limits which external or lower-trust sources can reach internal services. A public website may accept approved web traffic while database administration remains unreachable from the internet.

Outbound traffic

Leaving a host, network, zone, or application

Outbound policy limits destinations and services that internal systems may contact. This can reduce data leakage, unauthorized software communication, and malware command traffic while supporting required business use.

Firewall rules and the default-deny principle

A rule describes traffic conditions and an action. Rules are commonly evaluated in a defined order, so broad rules can accidentally override narrower intentions.

Common firewall rule criteria
CriterionQuestion answeredDefensive example
Source IP or zoneWhere did traffic originate?Only the protected management network may reach an administrator interface.
Destination IP or zoneWhich system or segment is being contacted?Guest traffic may reach the internet but not internal servers.
Port or serviceWhich logical service endpoint is requested?A public server exposes only the services required for its role.
ProtocolWhich communication protocol is used?Only approved, encrypted management protocols are permitted.
Application or identityWhich application, user, device, or workload is involved?An approved finance application reaches its database through a specific service.
Connection stateIs traffic starting a new connection or part of an expected established flow?Return traffic is accepted only when it matches tracked connection state.

Allow rule

Permits traffic that matches a documented, necessary use. It should be as narrow as practical and monitored according to risk.

Deny rule

Blocks prohibited communication. Important denials may be logged or alerted so defenders can detect mistakes and suspicious activity.

Default deny

If traffic does not match an approved allow rule, block it. This implements least privilege and reduces accidental exposure.

Limit unnecessary ports and services

Every reachable service expands the attack surface and must be patched, configured, authenticated, monitored, and supported. Disable services that have no business need and restrict necessary services to approved sources.

Firewall inspection types

TypeWhat it examinesStrengthLimitation
Packet-filtering firewallHeader fields such as addresses, ports, protocol, and directionFast, flexible control at network and transport layersLimited understanding of connection history or application content
Stateful inspection firewallHeader fields plus tracked connection stateRecognizes whether traffic fits an expected active connectionDoes not automatically understand every application action or encrypted payload
Proxy firewallTerminates one connection and creates another on behalf of a client or serverSeparates endpoints and can enforce application-specific policyAdds complexity, processing, compatibility, and availability considerations
Application-layer firewallApplication protocols and behavior, often at Layer 7Can distinguish permitted application use from traffic merely sharing a portNeeds current application knowledge and may not inspect protected content without an approved design
Next-generation firewallState, applications, identities, content, and integrated threat signalsCombines traditional policy with deeper application awarenessMore capability creates more tuning, privacy, performance, and management responsibility

Host, network, hardware, software, and cloud firewalls

Host-based

Protects one endpoint

Software on a laptop, server, or workload controls traffic for that host, including traffic from other internal devices.

Network-based

Protects a boundary

An appliance, virtual device, router function, or service controls traffic between networks, VLANs, zones, or sites.

Hardware appliance

Dedicated platform

A physical device provides firewall functions, often alongside routing, VPN, or inspection capabilities.

Software firewall

Runs on general or virtual systems

Can protect individual hosts or operate as a virtual network firewall with centrally managed policy.

Cloud firewall

Software-defined enforcement

Cloud-native rules, security groups, gateways, and managed services control traffic among virtual networks, workloads, and the internet.

Layered placement

More than the perimeter

Perimeter, internal, workload, and host firewalls can enforce different policies as part of defense in depth.

Web application firewalls have a specific purpose

A web application firewall (WAF) protects web applications by inspecting HTTP/HTTPS requests and responses according to application-layer rules. It is commonly placed logically between web users and a web application to detect or block suspicious request patterns, malformed input, automated abuse, or policy violations.

A WAF does not replace a general network firewall. A network firewall controls broader network connectivity; a WAF focuses on web application traffic. It also does not repair insecure application code, remove the need for testing, or guarantee that every web attack is blocked.

Firewalls support segmentation and defense in depth

Segmentation creates zones; firewalls enforce which traffic may cross their boundaries. A guest zone may reach the internet but not school records. A web server in a DMZ may reach an application service through one approved flow, while direct database administration remains blocked.

Least-privilege traffic flow

Define the source, destination, service, direction, identity, business owner, monitoring requirement, and review date. Avoid broad “any-to-any” access that turns a segmented design back into a flat network.

Logs, alerts, monitoring, and rule reviews

LOG

Record enough context such as time, action, source, destination, service, rule, device, and connection result.

ALERT

Escalate meaningful events such as repeated denials, policy changes, unusual outbound traffic, or access to sensitive zones.

REVIEW

Compare rules with current need and remove unused access, expired exceptions, duplicate rules, and shadowed rules.

CHANGE

Match modifications to approvals and document who requested, approved, implemented, tested, and validated the change.

TEST

Verify intended outcomes through authorized processes after deployment and significant changes.

Possible warning signs

  • New rules without change records
  • Sudden increases in denied or outbound traffic
  • Disabled logging or time drift
  • Unexpected services becoming reachable
  • Repeated connections to unusual destinations

Rule-review questions

  • Is the business need still valid?
  • Can the source, destination, service, or time be narrower?
  • Is the rule ordered correctly?
  • Are logs useful and reviewed?
  • Does the rule have an owner and review date?

Common firewall configuration mistakes

Overly broad allow rules

Rules permit more sources, destinations, ports, applications, or directions than the business task requires.

Incorrect rule order

A broad rule matches before a narrow deny or restriction, changing the intended result.

Forgotten temporary rules

Emergency or testing access remains after the approved period because it lacks an owner or expiry.

Unnecessary services

Old, unsupported, or unused services remain reachable and expand the attack surface.

Missing outbound controls

Defenders focus only on inbound threats and overlook unauthorized data transfer or malware communication.

Poor documentation and logging

Rules have unclear purpose, logs are missing, alerts have no owner, and the effective configuration drifts from policy.

Benefits and limitations of firewalls

Benefits

Control and visibility

  • Reduces unnecessary network exposure
  • Enforces segmentation boundaries
  • Limits inbound and outbound communication
  • Records policy decisions for detection and investigation
  • Applies consistent rules at strategic points
Limitations

One layer—not a shield against everything

  • Allowed traffic may still contain attacks
  • Encrypted traffic may limit inspection
  • Misconfiguration can create gaps
  • Threats can begin inside a permitted zone
  • Stolen credentials can make harmful traffic appear authorized

Firewalls cannot replace other safeguards

Patching removes known flaws. Strong authentication verifies identity. Encryption protects data. Endpoint and antivirus tools inspect host activity. User awareness reduces risky decisions. Backups and response plans support recovery. Firewalls complement every one of these controls.

Real-world firewall examples

Home

A router firewall blocks unexpected inbound internet connections, while host firewalls protect laptops from other local devices. Lesson: keep firmware current, restrict administration, and disable unused services.

School

Firewalls allow student devices to reach learning services but deny access to administrative systems and network management. Lesson: rules enforce role-based segmentation.

Office

A remote-access gateway accepts approved encrypted connections with MFA, while internal firewalls limit vendors to assigned systems. Lesson: identity, scope, logging, and expiry work together.

Data center

A public web tier sits in a DMZ, application servers occupy an internal zone, and databases accept only required application traffic. A WAF adds web-specific inspection. Lesson: different firewalls solve different boundary problems.

Cloud

Cloud security groups restrict workload connections, a managed firewall controls network egress, and a WAF protects the public application. Lesson: software-defined firewalls still need inventory, ownership, change control, and logs.

Watch: protecting networks with firewalls

As you watch, identify the traffic direction, inspection type, applicable rule, enforcement point, and supporting security layer.

Interactive knowledge check

Rule the Traffic

Choose the strongest defensive answer. The quiz works entirely in your browser and collects no personal information.

What the quiz covers

The ten questions assess inbound and outbound traffic, rule criteria, default deny, packet filtering, stateful inspection, proxy and application controls, placement, WAFs, segmentation, logging, mistakes, and limitations.

How scoring works

Answer every question, select Check my answers, review your score and explanations, then use Restart quiz to practice again.

Choose the strongest answer

0 of 10 answered

1. What is the primary function of a firewall?
2. Which statement correctly compares inbound and outbound traffic?
3. What does default deny mean?
4. What distinguishes stateful inspection from basic packet filtering?
5. What is the specific purpose of a web application firewall?
6. Which statement about firewall placement is accurate?
7. Which rule best supports least privilege?
8. What is a strong firewall-maintenance practice?
9. Why can a firewall not replace patching and authentication?
10. Which plan best demonstrates defense in depth?

AP® Cybersecurity study support

ACL

An access-control list containing rules that permit or deny network communication.

Egress filtering

Policy applied to outbound traffic leaving a host, zone, or network.

Five-tuple

Source address, destination address, source port, destination port, and protocol used to describe a flow.

Ruleset

The ordered collection of policy rules a firewall evaluates.

State table

A record of active connections used by a stateful firewall to evaluate expected traffic.

WAF

A web application firewall that focuses on HTTP/HTTPS application traffic.

Exam reasoning pattern

Identify the boundary, traffic direction, source, destination, service, state or application context, intended action, logging need, and supporting controls.

Continue studying

Review broader concepts using RevisionTown computer science resources, connect encryption with the cryptography guide, or plan retrieval practice with the AP® self-study guide.

Frequently asked questions

1. What is a firewall?

A firewall is a device, program, or cloud service that monitors and controls network traffic according to an approved security policy at a host or network boundary.

2. What is the difference between inbound and outbound traffic?

Inbound traffic enters a host, network, zone, or application from another context. Outbound traffic leaves it. Both directions require policies because either can carry legitimate or harmful communication.

3. What does default deny mean?

Traffic is blocked unless an explicit approved rule permits it. This applies least privilege and reduces accidental exposure from traffic that no one intentionally authorized.

4. How does stateful inspection work?

A stateful firewall tracks active connections and compares new traffic with expected connection state as well as addresses, ports, protocols, and rules.

5. What is the difference between a host and network firewall?

A host firewall controls traffic for one endpoint or workload. A network firewall controls traffic crossing a boundary between networks, zones, VLANs, sites, or cloud environments. They can work together.

6. What is a next-generation firewall?

An NGFW extends traditional packet filtering and stateful inspection with deeper application awareness and often identity, content, or integrated threat-prevention capabilities.

7. What does a web application firewall protect?

A WAF focuses on HTTP/HTTPS requests and responses to protect web applications from suspicious or policy-violating web traffic. It does not replace secure coding or general network controls.

8. Why should firewall rules be reviewed?

Business needs, systems, threats, and architectures change. Reviews remove unused access, narrow broad rules, expire temporary exceptions, correct ordering, confirm ownership, and detect unauthorized modifications.

9. Can a firewall block every cyberattack?

No. Allowed or encrypted traffic may contain attacks, threats may begin inside a zone, credentials may be stolen, endpoints may be vulnerable, and rules may be misconfigured. Firewalls are one layer.

10. Why limit unnecessary ports and services?

Every reachable service expands the attack surface and requires secure configuration, authentication, patching, monitoring, and support. Removing unnecessary services reduces exposure and operational complexity.

Trusted references

AP® is a trademark registered by the College Board, which is not affiliated with and does not endorse this page. This lesson provides defensive cybersecurity education. Firewall configuration, monitoring, and testing must be authorized and follow applicable policies, privacy requirements, change control, and law.

Shares: