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.
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.
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.
Types of Firewalls
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.
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.
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
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.
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.
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
How to Evaluate a Firewall Rule Set
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.
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:
2. 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.
Common Mistakes
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?
Rule 1: ALLOW TCP Any → 10.0.0.5 :443
Rule 2: DENY TCP Any → 10.0.0.5 :*
Rule 3: ALLOW TCP Any → Any :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?
Rule 1: DENY TCP Any → Any :22
Rule 2: ALLOW TCP 192.168.1.50 → Any :22