The Plain Picture#
A security guard at a building's gate with a list: "Deliveries to flat 443 — allowed from anyone. Flat 22 (the manager's office) — only visitors from head office. Everyone else — turned away."
The Real Names#
A firewall allows or blocks traffic using rules based on source/destination IP address (or CIDR range), port and protocol.
A stateful firewall remembers connections: if it allowed a connection out, it automatically allows the replies back in. Almost all modern firewalls are stateful.
A stateless firewall checks each packet on its own, so you must write rules for both directions.
In the cloud: AWS security groups are stateful firewalls attached to each server; AWS network ACLs are stateless rules on a whole subnet. GCP has VPC firewall rules.
Under the Hood#
StudyBuddy's three tiers (Networking 1: Addresses and Routing Ch 11), each with its own security group:
internet ──443──▶ [ load balancer ] allow tcp/443 from 0.0.0.0/0 (everyone)
│
│ 8000
▼
[ app servers ] allow tcp/8000 only from the load balancer's group
│
│ 5432
▼
[ database ] allow tcp/5432 only from the app servers' groupPrinciple of least privilege: open only the exact ports, to the exact sources, that are needed. The database accepts connections only from app servers, only on 5432. Even if an attacker got into the load balancer, they couldn't reach the database directly.
Two ways to reject:
Drop — silently ignore the packet. The client sees a timeout (Ch 5). Common for internet-facing rules.
Reject — reply with a reset/error. The client sees "connection refused" immediately.
Gotchas
0.0.0.0/0on port 22 or 5432 — SSH or the database open to the whole internet — is one of the most common real security mistakes. Automated scanners find such servers within minutes."It times out" usually means a firewall (or security group) is dropping the traffic — check the rules on both ends, and any subnet-level stateless rules.
Check yourself
3 questionsWhat's the difference between a stateful and a stateless firewall?
Show answerHide answer
Stateful remembers allowed connections and lets replies back automatically; stateless checks each packet alone, so both directions need rules.
Write the rule (in words) that lets only app servers reach the database.
Show answerHide answer
Allow TCP port 5432 inbound, only from the app servers' security group (or their subnet range); deny everything else.
A client gets a timeout, not "refused". What's the likely cause?
Show answerHide answer
A firewall silently dropping the packets (or no route).