0Pricing
Cloud & IT Cert Prep · Lesson

Firewalls: Packet Filtering vs Next-Gen

Compare stateless packet filtering, stateful inspection, and next-generation firewalls with application awareness, IPS, and SSL inspection.

Firewalls: Packet Filtering vs Next-Gen is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is a Firewall?

A firewall is a network security device (hardware or software) that monitors and controls incoming and outgoing traffic based on predefined rules. Firewalls sit between trusted internal networks and untrusted external networks, acting as a gatekeeper. They are a foundational perimeter control, but modern attacks that use encrypted channels or lateral movement within trusted zones highlight why firewalls alone are insufficient and must be combined with other layers of defense.

Packet Filtering Firewalls

Packet filtering firewalls (also called stateless firewalls) inspect each packet in isolation based on header fields: source IP, destination IP, source port, destination port, and protocol. They apply simple allow/deny rules called ACLs (Access Control Lists). Because they examine each packet independently, they cannot track whether a packet is part of an established session, making them vulnerable to attacks that forge expected header values or exploit multi-packet vulnerabilities.

# iptables packet filter example (Linux)
# Allow established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Block inbound Telnet
iptables -A INPUT -p tcp --dport 23 -j DROP

# Allow SSH from specific subnet
iptables -A INPUT -p tcp -s 10.0.0.0/24 --dport 22 -j ACCEPT

Stateful Inspection Firewalls

Stateful inspection firewalls maintain a state table that tracks active connections. When a packet arrives, the firewall checks whether it belongs to an already-established session. This allows return traffic to pass automatically without explicit rules. Stateful firewalls are far more secure than packet filters because they can detect packets that do not belong to a valid session — such as unsolicited ACK packets used in stealth scans — and can enforce connection-level policies.

# Example state table entries:
# ESTABLISHED: connection is in use
# RELATED:     packet is related to existing connection (e.g. FTP data)
# NEW:         first packet of a new connection
# INVALID:     packet doesn't match any known state

# Check conntrack table on Linux
conntrack -L

Next-Generation Firewalls (NGFW)

Next-generation firewalls (NGFW) add deep packet inspection and application awareness beyond stateful tracking. An NGFW can identify the application generating traffic — not just the port — using protocol dissection and machine learning. Key NGFW capabilities include application control (block Dropbox regardless of port), user identity integration (rules tied to AD groups), integrated IPS, and SSL/TLS inspection. Vendors include Palo Alto Networks, Fortinet, Check Point, and Cisco Firepower.

# NGFW capabilities:
# - Layer 7 application identification (App-ID)
# - User-ID (Active Directory integration)
# - Content-ID (URL filtering, malware scanning)
# - SSL decryption (forward proxy)
# - Integrated IPS signatures

Firewall Rules and ACL Order

Firewall rules are evaluated in top-down order — the first matching rule wins. This means more specific rules must appear before more general ones. An implicit deny all rule at the bottom blocks any traffic not explicitly permitted. Common mistakes include placing a broad allow rule before a specific deny, shadowing (a rule that never matches because a prior rule always matches first), and forgetting to allow return traffic or ICMP error messages that applications depend on.

# Firewall ACL example (conceptual order matters):
# Rule 1: ALLOW TCP src ANY dst 10.0.1.5 dport 443
# Rule 2: DENY  TCP src ANY dst 10.0.1.5 dport ANY
# Rule 3: ALLOW TCP src 10.0.0.0/8 dst ANY dport 22
# Rule 4: DENY  ANY (implicit deny-all)
#
# If Rule 2 were placed before Rule 1, HTTPS would be blocked.

Web Application Firewalls (WAF)

A WAF (Web Application Firewall) operates at Layer 7 and is specifically designed to protect web applications from attacks like SQL injection, XSS, and CSRF. Unlike NGFWs that protect network traffic broadly, a WAF understands HTTP and HTTPS semantics — inspecting URLs, headers, cookies, and request bodies. WAFs can operate in detection mode (log but don't block) or prevention mode (block malicious requests). AWS WAF, Cloudflare, and Imperva are common commercial solutions.

# WAF rule example (pseudocode):
# Block requests with SQL injection patterns:
#   URI or body contains: ' OR 1=1 --
#   URI or body contains: UNION SELECT
#   URI or body contains: ; DROP TABLE
#
# Block XSS patterns:
#   URI or body contains: <script>
#   URI or body contains: javascript:

SSL/TLS Inspection on Firewalls

Because most traffic is now encrypted with HTTPS, threats can hide inside TLS sessions. SSL/TLS inspection (also called SSL interception or decryption) allows NGFWs to act as a man-in-the-middle proxy: the firewall terminates the client's TLS connection, inspects the plaintext, and re-encrypts it toward the destination. This enables malware scanning and DLP within encrypted tunnels. The firewall's certificate must be trusted by clients, usually distributed via Group Policy to corporate devices.

# SSL inspection flow:
# Client -> [TLS session A: Client trusts FW cert] -> NGFW
# NGFW   -> [TLS session B: NGFW validates server cert] -> Server
#
# The NGFW can now inspect plaintext between sessions A and B.
# Pinned-cert apps (banking, some OS updates) may break.

Firewall Placement in Network Architecture

Firewalls are most effective when positioned at trust boundaries. A common design places a perimeter firewall between the internet and the DMZ, and an internal firewall between the DMZ and the internal network. This creates a screened subnet where public-facing servers (web, mail) are isolated so that if they are compromised, the attacker cannot directly reach internal systems. Modern designs also place firewalls between internal segments to limit lateral movement.

# Three-zone firewall architecture:
# [Internet]
#    |
# [Perimeter NGFW]
#    |
# [DMZ: web servers, mail relay, DNS]
#    |
# [Internal NGFW]
#    |
# [Internal network: workstations, servers, databases]

Intrusion Detection vs Prevention Systems

An IDS (Intrusion Detection System) monitors traffic and generates alerts when it identifies suspicious patterns, but it does not block traffic. An IPS (Intrusion Prevention System) sits inline and can actively drop malicious packets or reset connections in real time. Most modern NGFWs include an integrated IPS. Detection methods include signature-based (matching known attack patterns) and anomaly-based (detecting deviations from a learned baseline).

# IDS/IPS placement options:
# NIDS (Network): monitors traffic on a network segment
#   -> requires port mirroring (SPAN port) or network tap
# HIDS (Host): monitors system calls and file changes on a host
#   -> example: OSSEC, Wazuh
# Inline IPS: traffic must pass through the device
#   -> can block in real time but also becomes a bottleneck

Unified Threat Management (UTM)

A UTM (Unified Threat Management) appliance consolidates multiple security functions into a single device: firewall, IPS, antivirus, VPN, web filtering, and sometimes email security. UTMs are popular in small-to-medium businesses because they simplify management and reduce cost. The trade-off is that a single appliance represents a single point of failure and may not offer the performance or depth of purpose-built solutions. The term UTM is largely superseded by NGFW in enterprise contexts.

Comparing Firewall Types for the Exam

The Security+ exam tests your ability to select the right firewall type for a given scenario. Packet filtering is fast but stateless and easily evaded. Stateful inspection tracks sessions and is the baseline for modern networks. NGFW adds application awareness, user identity, and integrated IPS — the right choice for enterprise perimeters. WAF specifically protects web applications at Layer 7 HTTP. Always match the control to the threat: a WAF won't stop a port scan, and a packet filter won't stop SQL injection.

Quick Check

Test your understanding of CompTIA Security+ (SY0-701) concepts from this lesson.

Lesson Recap

In this lesson you learned: packet filtering firewalls are stateless and evaluate each packet by header fields only, stateful firewalls track connection states to allow return traffic and detect anomalous packets, and next-generation firewalls add application awareness, user identity, and integrated IPS for deeper inspection. Next up we explore network segmentation and VLANs.

Frequently asked questions

Is the “Firewalls: Packet Filtering vs Next-Gen” lesson free?

Yes — the full text of “Firewalls: Packet Filtering vs Next-Gen” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.

What will I learn in “Firewalls: Packet Filtering vs Next-Gen”?

Compare stateless packet filtering, stateful inspection, and next-generation firewalls with application awareness, IPS, and SSL inspection. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cloud & IT Cert Prep?

No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Firewalls: Packet Filtering vs Next-Gen” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cloud & IT Cert Prep lesson?

Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. TCP/IP Model and Common Ports
  2. Firewalls: Packet Filtering vs Next-Gen
  3. Network Segmentation and VLANs
  4. Common Network Attacks: DoS, Spoofing, and MITM
← Back to Cloud & IT Cert Prep