01 / 20

Firewalls
Gatekeepers of Your Network

Understand how firewalls filter traffic using allow and deny rules, and learn the critical difference between stateful and stateless inspection.

Cyber Security

What Is a Firewall?

A firewall is a network security device (hardware, software, or both) that monitors incoming and outgoing network traffic and decides whether to allow or block specific packets based on a defined set of security rules.

Internet Firewall Rules Engine ALLOW DENY Internal Network

Why Firewalls Matter

Without a firewall, every device on your network is directly exposed to the internet: any attacker, bot, or worm can attempt to connect to any open port on any machine.

✕ Without Firewall
All ports exposed. Malware, port scans, and unauthorized connections reach internal hosts freely.
✓ With Firewall
Only explicitly permitted traffic passes. Unwanted connections are silently dropped or actively rejected.

Types of Firewalls

Hardware
Dedicated physical appliance sitting between the network and the internet. Common in enterprise environments.
Software
Program installed on a single host (e.g., Windows Firewall). Protects the individual device.
Cloud
Firewall-as-a-Service (FWaaS) hosted in the cloud. Scales easily and protects distributed networks.

Anatomy of a Network Packet

Every piece of data traveling across a network is broken into packets. Each packet has a header containing metadata that firewalls inspect to make their decisions.

HEADER Source IP: 192.168.1.10 Dest IP: 10.0.0.5 Protocol: TCP Port: 443 PAYLOAD (actual data)

Firewall Rules: Allow and Deny

A firewall's behavior is defined by an ordered list of rules. Each rule specifies a condition and an action. The firewall checks packets against rules from top to bottom and executes the first matching rule.

# Rule Action Protocol Source Dest Port
1 ALLOW TCP Any WebServer 443
2 ALLOW TCP Admin_IP Any 22
3 DENY TCP Any Any 22
4 DENY ANY Any Any * # Default deny

Allow vs. Deny: The Two Actions

ALLOW
Permits the packet to pass through. The connection proceeds normally. Also called ACCEPT or PERMIT.
DENY
Blocks the packet. It can DROP (silently discard) or REJECT (discard and send an error response back to the sender).

Stateless Packet Filtering

A stateless firewall examines each packet independently. It has no memory of previous packets. Every single packet is judged solely against the rule set based on its header information.

PKT 1 PKT 2 PKT 3 Stateless No Memory ALLOW ALLOW DENY Network

Stateful Packet Inspection

A stateful firewall tracks the state of active connections in a state table. It knows whether a packet belongs to a NEW connection, an ESTABLISHED connection, or is RELATED to an existing one.

Client SYN Stateful Firewall State Table Client → Server ESTABLISHED TCP :443 ✓ NEW Server SYN-ACK ✓ Auto Rogue Not in table

Stateless vs. Stateful

Stateless Stateful
Inspects Individual packet headers only Packet headers + connection context
Memory None: each packet treated in isolation Maintains a state table of active sessions
Return Traffic Needs explicit ALLOW rule for return packets Automatically allowed if session is tracked
Speed Faster: less processing per packet Slightly slower: table lookups required
Security Less secure: cannot detect spoofed replies More secure: rejects untracked packets
Use Case Simple ACLs, high-speed routers Enterprise perimeter, most modern firewalls

Anatomy of a Firewall Rule

1
Rule Number / Priority: Determines the order of evaluation. Lower numbers are checked first.
2
Action: What to do: ALLOW, DENY (DROP), or REJECT.
3
Protocol: Which protocol to match: TCP, UDP, ICMP, or ANY.
4
Source / Destination: IP addresses or ranges. Can be specific IPs, subnets, or "Any".
5
Port: Destination port number (e.g., 80 for HTTP, 443 for HTTPS, 22 for SSH).

How to Evaluate a Firewall Rule Set

1
Identify the incoming packet's attributes: source IP, destination IP, protocol, and destination port.
2
Start at Rule 1 (top of the list). Compare the packet's attributes to the rule's conditions.
3
If it matches: execute the rule's action (ALLOW or DENY). Stop checking further rules.
4
If it doesn't match: move to the next rule and repeat.
5
If no rules match: apply the default policy (typically DENY ALL).

Example 1: Web Server Access

A company wants its web server (IP: 10.0.0.5) to accept HTTPS traffic from any source, but block all other traffic.

# Rule Action Protocol Source Dest Port
1 ALLOW TCP Any 10.0.0.5 443
2 DENY ANY Any 10.0.0.5 *

Example 2: Rule Order Trap

An admin wants to allow SSH from 192.168.1.100 but deny SSH from all other IPs. They write these rules:

✕ Wrong Order
1. DENY TCP Any → Any :22
2. ALLOW TCP 192.168.1.100 → Any :22
✓ Correct Order
1. ALLOW TCP 192.168.1.100 → Any :22
2. DENY TCP Any → Any :22

Example 3: Stateful Advantage

A user inside the network opens a web page. The outbound request goes to port 443. The server responds from port 443 back to a random high port on the user's machine.

Stateless Approach
Must add a rule allowing inbound traffic from any source on port 443 to any high port. This opens a dangerous hole: an attacker could send unsolicited traffic from port 443.
Stateful Approach
The firewall records the outbound connection in its state table. The return packet is automatically matched to the session and allowed: no extra rule needed.

Common Mistakes

✕ Wrong Rule Order
Placing a broad DENY before a specific ALLOW. The broad rule fires first and blocks desired traffic.
✕ Default Allow
Using "allow all" as the default policy. Any traffic not explicitly blocked passes through: massive security gap.
✕ Confusing Stateful / Stateless
Assuming a stateless firewall tracks connections. It does not: every packet is evaluated independently.

Question 1 of 5

A stateful firewall differs from a stateless firewall primarily because it:

Question 2 of 5

Given these firewall rules, what happens to a TCP packet from any source to 10.0.0.5 on port 80?

Question 3 of 5

Which firewall policy approach is considered most secure?

Question 4 of 5

A user inside the network browses a website. The stateful firewall allows the outbound request. When the web server sends a response packet back, the stateful firewall:

Question 5 of 5

An administrator writes these two rules. What is the problem?