How do firewalls inspect packets?
Every packet that tries to enter or leave a network has to pass a checkpoint first. Meet Packet-y — a little envelope of data — as it goes through three increasingly strict security guards on its way into an office building.
📽️ Comic Strip: Packet-y's Day at the Checkpoint
The whole story in six panels, before we break it down level by level.
🧱 So what actually is a firewall?
Not a wall of fire — a security checkpoint that every packet must pass through.
- A firewall sits between two networks and decides, packet by packet: let it through, or block it?
- Some firewalls just glance at the envelope, others actually open the box — that's what "levels of inspection" means.
- Every decision follows a default policy: "block everything unless explicitly allowed" (default-deny, safer) or "allow everything unless explicitly blocked" (default-allow, riskier).
sudo ufw status verbose (Ubuntu/Debian)
sudo firewall-cmd --state (RHEL/CentOS)
netsh advfirewall show allprofiles (Windows)
Each of these tells you the current default policy — deny or allow — for your own machine's firewall.
🏠 Where does a firewall actually live?
Not one guard — often several, stationed at different gates.
- Network firewall — sits at the front gate of a whole network (built into a router, or a dedicated appliance). Protects everyone behind it at once.
- Host firewall — runs on each individual device (Windows Defender Firewall, macOS firewall, Linux ufw/firewalld). Useful "defense in depth."
- In the cloud, this splits into Security Groups (instance-level) and Network ACLs (subnet-level) — the same two-layer idea, renamed.
📦 Quick recap: what's inside a packet?
Different firewall levels read different layers of the same envelope.
Guard 1: "Show me your labels"
- Reads only outer headers: source IP, destination IP, source port, destination port, protocol.
- Compares them against a static list of rules called an Access Control List (ACL).
- Has no memory — each packet is judged on its own.
- Fast, but easy to fool with a crafted header.
sudo iptables -L -n -v
sudo firewall-cmd --list-all (RHEL/CentOS)
netsh advfirewall firewall show rule name=all (Windows)
Guard 2: "Didn't I just see you leave?"
- Still reads headers, but also tracks ongoing connections in a state table.
- If your computer opened a connection out, the matching reply is automatically allowed back in.
- An unsolicited "reply" to a conversation that never started is dropped.
- This is what most home routers and office firewalls actually run.
sudo conntrack -L
netstat -ano | findstr ESTABLISHED (Windows)
Wireshark filter: tcp.flags.syn==1 && tcp.flags.ack==0
Guard 3: "I'm actually opening the box"
- Reads all the way to the payload / application layer.
- Can block a specific URL, file type, or keyword — even if the port looks normal.
- Compares content against known malware signatures.
- More thorough, but slower.
sudo tcpdump -A port 80 | grep "Host:"
Wireshark filter: http.request or tls.handshake.extensions_server_name
Note: this only works on unencrypted traffic; for HTTPS, a real DPI firewall must first decrypt it.
🚨 Attacks a firewall helps block
Real threats, and which guard catches each one.
🔎 Port scanning
An attacker knocks on every port. Even Level 1 helps — closed ports drop probes so the attacker learns nothing.
🌊 SYN flood (DoS)
Thousands of half-open handshakes. Stateful firewalls (Level 2) cap or drop excess before the server drowns.
🎭 IP spoofing
Faked "from" address. Firewalls verify the packet arrived on the correct interface ("reverse path filtering").
🦠 Malware delivery
Bad content hidden in normal-looking traffic. Only Level 3 (DPI) actually reads the content and catches it.
🎓 Level Up: Next-Gen Firewalls
Modern firewalls combine every guard above, plus superpowers.
🕵️ Intrusion Prevention (IPS)
Watches for attack patterns across many packets, like someone jiggling the same door 500 times.
👤 User & app awareness
"Amit can use video calls, but not file-sharing apps" — identifies the app and user, not just the port.
🔓 TLS/SSL inspection
Decrypts HTTPS at the checkpoint, inspects it, then re-encrypts it — like a guard with special see-through glasses.
🌐 Live threat intelligence
Constantly-updated blocklists — a signature spotted an hour ago is already blocked at your gate today.
🏝️ DMZ — the visitor lobby
Public servers sit in a separate zone — reachable from the internet, firewalled off from internal systems.
🔄 NAT — one address, many devices
Many internal devices share one public IP; NAT rewrites addresses as packets cross the firewall.
🧩 The three levels, side by side
| Level | OSI layer read | Remembers past packets? | Sees actual content? | Speed |
|---|---|---|---|---|
| Packet Filter | Network / Transport (3-4) | No | No | ⚡ Fastest |
| Stateful | Network / Transport (3-4) | Yes — state table | No | ⚡ Fast |
| Deep Packet Inspection | Application (7) | Yes | Yes | 🐢 Slower, more thorough |
