Ravindra BagaleCourses & study guides मराठी Track your progress

What Is a Firewall and Its Types: Packet, Stateful, NGFW, WAF and UTM

Before you touch iptables or AWS Network Firewall, you need a clear map of what a firewall is. Lagos clinic CTO Adaeze Okonkwo and Pune SaaS founder Vikram Patil both said the same thing in class: "We hear WAF, NGFW, SG, NACL, UTM — which one do we buy?" This chapter answers with a building-guard story, a vertical diagram and a comparison table. Deep SG vs NACL stays in the class chapter; WAF/Shield stay in their chapters — we only link.

What you'll learn in this chapter

  • Explain a firewall with a building-security-guard story
  • Name packet-filter, stateful, proxy, circuit-level, NGFW, WAF, UTM
  • Contrast host vs network and hardware vs software vs cloud
  • Read a vertical path diagram and a comparison table
  • Link (not copy) SG vs NACL, CloudFront+WAF and WAF/Shield chapters

1. Everyday example: the building security guard

Think of your office building. A security guard at the gate is a firewall. Visitors are packets (or connections, or HTTP requests). The visitor book is the rule set. The guard can: (1) check only the ID card number — like a packet filter that looks at IP and port; (2) remember that this courier was already signed in upstairs — like stateful inspection; (3) open the parcel and read the letter — like an application / proxy firewall or WAF; (4) call the floor receptionist on a phone line you already opened — like a circuit-level gateway; (5) also check temperature, banned-list photos and "are you a robot?" — like a next-gen firewall (NGFW).

One guard at the street gate is a network-based firewall. A lock on each apartment door is a host-based firewall. A rented guard company in the cloud is a cloud firewall. A "do everything" booth that also sells SIM cards and CCTV is UTM (Unified Threat Management) — convenient, but one booth fails and many services suffer.

2. Vertical diagram: where firewalls sit

Internet → Edge (NGFW / cloud FW / WAF) → Network FW → Host FW → AppEach layer sees a different question
Miss a layer = gap attackers love
Internet / attackers Edge: Cloud FW / NGFW / WAFL3–L7 at the front door Network firewall (VPC / DC)Subnets, inspection VPC Host firewall (iptables/ufw)Per OS / per instance App controls (auth, WAF rules)HTTP verbs, tokens, bots Your data / workload
Vertical path: Internet → edge → network → host → app → data. Skip a box and you leave a gap.

3. Why do we need firewalls?

Why do we need this?

Networks are shared. Without a filter, every port on every host is a door. Attackers scan, flood, inject and pivot. A firewall is the policy point that says allow, deny or inspect before traffic reaches the workload.

  • Reduce the attack surface (close what you do not need)
  • Enforce least privilege between tiers (web ≠ database)
  • Log denied attempts for forensics
  • Meet compliance (PCI, ISO, RBI) that demands perimeter controls

4. What is a firewall?

What is it?

A firewall is a control that evaluates network traffic against a rule set and decides allow, deny or inspect. Rules can look at addresses, ports, connection state, application payloads or threat intelligence. Placement can be on a host, on a network appliance, or as a cloud service.

5. Type 1 — Packet-filter (stateless)

Looks at each packet alone: source/dest IP, protocol, ports. No memory of "this is a reply to a request we allowed". Fast and cheap. Classic example: many Network ACL (NACL) behaviours on AWS — see the deep class chapter Security Group vs NACL (we do not repeat that lab here).

  • Pros: simple, high throughput, predictable
  • Cons: must open ephemeral return ports carefully; easy to misconfigure
  • Industry: edge routers, some cloud NACLs, old border routers

6. Type 2 — Stateful inspection

Remembers connections. If you allowed outbound TCP to 443, the return packets belonging to that flow are allowed automatically. Security Groups on AWS are stateful — again, details in the SG vs NACL chapter.

  • Pros: fewer rules, safer defaults for return traffic
  • Cons: state table memory; asymmetric routing can break state
  • Industry: most enterprise perimeter firewalls, cloud SGs

7. Type 3 — Application / proxy firewall

Terminates the client connection and opens a new one to the server (or inspects deeply at the application protocol). Can enforce HTTP methods, URLs, SMTP commands. A reverse proxy with security policies is in this family. WAF is the specialised web flavour — deep chapters: CloudFront+WAF survey and AWS WAF explained.

8. Type 4 — Circuit-level gateway

Works around session / circuit setup (often SOCKS-style ideas): once a circuit is approved, bytes flow without deep app inspection. Lighter than a full proxy; weaker visibility into payloads.

9. Type 5 — Next-gen firewall (NGFW)

Combines stateful firewalling with application awareness, intrusion prevention (IPS), sometimes sandboxing and threat intel feeds. Vendors: Palo Alto, Fortinet, Cisco, Check Point, and cloud NGFW offerings. On AWS you will also meet AWS Network Firewall (Suricata-compatible) in chapter 3 of this set.

10. Type 6 — Web Application Firewall (WAF)

Specialises in HTTP/HTTPS: SQLi, XSS, bots, rate limits, geo, OWASP rules. Not a replacement for network firewalls — it sits where web traffic lives (CDN, ALB, API Gateway). For DDoS layers and Shield, see Shield Standard vs Advanced and the DDoS-resilient project.

11. Host-based vs network-based

KindWhere it runsExample
Host-basedOn the OS of one machineiptables, nftables, firewalld, ufw, Windows Firewall
Network-basedInline on a path many hosts shareHardware NGFW, AWS Network Firewall, VPC NACL

Next chapter is the Linux host-firewall hands-on. The broader hardening survey (SELinux, fail2ban, auditd…) lives in Linux security hardening — link, do not duplicate.

12. Hardware vs software vs cloud firewall

FormWhat you buyWhen it fits
HardwareAppliance in a rackHigh fixed throughput in a DC you own
SoftwareImage/agent on a VM or hostFlexible, DIY Linux FW, virtual NGFW
CloudManaged service billed hourlyElastic scale, multi-AZ, less rack work

13. UTM — Unified Threat Management

One box (or one license) that bundles firewall + antivirus + web filter + VPN + sometimes email filter. Popular in small offices (example: Jaipur dental clinic of Dr. Meera Sharma wanting one appliance). Trade-off: simplicity vs single point of failure and weaker best-of-breed depth.

14. Comparison table

TypeState?InspectsTypical place
Packet filterNoIP/port/protocolRouter / NACL
StatefulYesFlows + portsSG / perimeter FW
Proxy / appYesApp protocolsReverse proxy
Circuit-levelSessionCircuit setupSOCKS-style gateways
NGFWYesApps + IPS + intelEdge / inspection VPC
WAFHTTP stateHTTP/HTTPS payloadsCDN / ALB / API
UTMYesMany features bundledSMB edge

15. Multi-industry snapshots

  • Healthcare (Adaeze Okonkwo, Lagos): network FW between EMR and internet; WAF on patient portal; host FW on jump hosts.
  • Fintech (Arjun Mehta, Mumbai): NGFW/IPS on egress; WAF on /login; SG tiers in VPC.
  • Ecommerce (Lucas Meyer, Berlin): CloudFront+WAF edge; Network Firewall for east-west; ufw on bastions.
  • Education (Sofia Alvarez, Bogotá): UTM for small campus; migrate critical apps to cloud FW later.
  • Manufacturing (Kenji Watanabe, Osaka): OT network segmented by industrial FW; IT uses NGFW.

16. Lab: map your current stack to the table

How to do it (step by step)

  1. List every filter you already run (SG, NACL, ufw, WAF, vendor NGFW).
  2. Mark each as packet / stateful / proxy / NGFW / WAF / UTM.
  3. Draw the vertical path for one public app (use the diagram above).
  4. Circle gaps (e.g. no host FW on bastion, or no WAF on login).
  5. Write one ticket per gap; link the matching deep chapter.

Cleanup

  1. This lab is paper/architecture only — no cloud spend.
  2. Store the diagram in your team wiki.

17. Firewall decision checklist

  1. Write the threat in one sentence (scan, SQLi, malware DNS, lateral SSH).
  2. Pick the layer: packet / stateful / proxy / NGFW / WAF / DNS / host.
  3. Pick the form: host tool, network appliance, or cloud service.
  4. Default deny or default allow? Write it down.
  5. Plan allow tests and deny tests before go-live.
  6. Plan logging destination (file, CloudWatch, SIEM).
  7. Name the on-call for false positives.
  8. Link the deep chapter you will not duplicate (SG/NACL, WAF, hardening).
  9. Estimate monthly cost (especially Network Firewall).
  10. Schedule a reboot or failover test for persistence.

18. Copy-paste quick commands

# --- Host (Ubuntu ufw) ---
sudo ufw status verbose
sudo ufw allow OpenSSH && sudo ufw allow 80/tcp && sudo ufw enable

# --- Host (RHEL firewalld) ---
sudo firewall-cmd --permanent --add-service=http && sudo firewall-cmd --reload

# --- Host (nft) ---
sudo nft list ruleset

# --- AWS pointers (details in linked chapters) ---
aws ec2 describe-security-groups --group-ids $SG
aws wafv2 list-web-acls --scope REGIONAL --region ap-south-1
aws network-firewall list-firewalls --region ap-south-1
aws route53resolver list-firewall-rule-groups --region ap-south-1

19. More industry stories

  • Retail POS (Kenji, Osaka): host FW on till PCs; network FW between stores and HQ; WAF only on ecommerce, not on private VPN APIs.
  • Media streaming (Priya, Pune): CloudFront+WAF for viewers; Network Firewall for origin admin VPC; Shield Advanced on match-day.
  • Gov portal (Fatima, Rabat): FMS mandates WAF CRS + DNS Firewall across ministries; local teams cannot disable.
  • Startup (Diego, São Paulo): start with SG+ufw+CloudFront WAF; add Network Firewall when east-west grows.
  • Logistics (Mei, Singapore): DNS Firewall blocks sinkholes; Suricata drops known C2 on inspection VPC.

20. Glossary (short)

TermMeaning
NetfilterLinux kernel packet filter framework
SuricataIDS/IPS engine; Network Firewall stateful dialect
5-tuplesrc IP, dest IP, proto, src port, dest port
East-westTraffic between workloads inside the cloud/DC
North-southTraffic in/out to internet or partners
Default denyIf no rule matches, drop
False positiveLegit traffic blocked by mistake

21. Practice: explain out loud

  1. 60 seconds: building-guard story for firewall types.
  2. 60 seconds: iptables vs nftables vs firewalld vs ufw.
  3. 60 seconds: SG vs NACL vs Network Firewall vs WAF.
  4. 60 seconds: inspection VPC with Transit Gateway.
  5. Record yourself once; fix filler words; record again.

22. Safe lab hygiene

  • Never practice DROP rules on a production SSH session without console access.
  • Tag every cloud lab resource with owner and expiry.
  • Keep a written rollback: old ruleset file or SG snapshot.
  • Prefer allowlists over giant denylists when starting.
  • After lab, delete Network Firewall — it bills hourly.
  • Networking basics / ports — foundations before filters.
  • SG vs NACL class — stateful vs stateless on AWS VPC.
  • Linux hardening survey — SELinux, fail2ban, auditd beyond FW.
  • CloudFront+WAF survey — CDN/HTTPS + light WAF.
  • WAF explained / hands-on / Shield / DDoS project — L7 and DDoS depth.

24. Rule-writing workshop

Write rules in English first, then translate to the tool. Bad: "block bad stuff". Good: "Drop TCP 445 from 0.0.0.0/0 on INPUT; allow TCP 445 only from 10.0.0.0/16".

  1. Name the direction: inbound, outbound, or east-west.
  2. Name the 5-tuple or domain or HTTP path.
  3. Name the action: accept, drop, alert, challenge.
  4. Name the hit counter / log you will check.
  5. Name the rollback (previous ruleset file).
  6. Peer-review with someone who did not write it.

25. Sample allow / deny matrix

FlowSGHost FWEdge WAFNetwork FW
Public HTTPS to web80/443 from 0.0.0.0/080/443CRS+rate on /loginusually not on edge path
SSH to bastion22 from corp CIDR22 corp onlyn/aoptional geo/IP
App to DB3306 from app SGoptional deny othersn/aeast-west inspect optional
Private egress DNS53 via resolverallown/aDNS FW lists + NF domain

26. Ten oral drill questions

  1. Say three differences between packet filter and stateful.
  2. Name four Linux host firewall tools.
  3. Why does connection refused ≠ filtered?
  4. What is an inspection VPC for?
  5. When is UTM a good first buy?
  6. Where do Suricata rules run on AWS?
  7. What does Firewall Manager stop?
  8. Why link SG vs NACL instead of rewriting?
  9. Give one healthcare and one fintech firewall story.
  10. What do you delete first in lab cleanup for cost?

27. Common errors and fixes

Each row is a real mistake students and juniors hit. Read the fix before you panic.

Error / symptomFix
Confusing WAF with network firewallWAF = HTTP; network FW = IP/port/state. Use both.
Expecting SG to stop SQLiSG has no HTTP vision — need WAF.
Opening NACL ephemeral range wrongStudy SG vs NACL chapter return-traffic patterns.
Buying UTM then skipping patchesUTM still needs updates or signatures rot.
Host FW off "for debugging" left offCalendar reminder to re-enable.
Asymmetric routing breaking stateful FWFix routes or use stateless carefully.
No deny loggingEnable logs before an incident.
One fat allow-any ruleReplace with least privilege.
Thinking cloud FW replaces host FWDefense in depth — keep bastion host FW.

28. Troubleshooting checklist

  1. Can users reach the app? If yes, which layer allowed it — edge, network, host?
  2. Check default policy: default-deny or default-allow?
  3. For stateful issues, inspect connection tables / flow logs.
  4. For HTTP attacks, jump to WAF sampled requests — not SG.
  5. Confirm you are not double-NATing past the inspection hop.

29. FAQ

Q. Is a Security Group a firewall?

Yes — a managed stateful virtual firewall for ENIs. Deep dive in the SG vs NACL chapter.

Q. Do I still need iptables if I have cloud SG?

Yes on bastions and when OS-level ports must be locked even from same SG peers.

Q. WAF vs NGFW — pick one?

Different layers. NGFW/network for L3–L7 apps broadly; WAF for HTTP apps at the edge. Often both.

Q. What is UTM good for?

Small sites wanting one appliance. Grow out when you need best-of-breed.

Q. Can I skip host firewalls in the cloud?

No — same-SG peers and bastions still need OS locks.

Q. Where should I start learning?

Types chapter → Linux hands-on → AWS cloud firewalls → linked WAF/Shield set.

30. Interview Q&A

Q. Explain firewall types to a non-engineer.

Use the building-guard story: ID check, memory of visitors, opening parcels, all-in-one booth.

Q. Packet filter vs stateful?

Packet = each packet alone; stateful = tracks connections and return traffic.

Q. Where does WAF sit vs Network Firewall?

WAF on HTTP paths (CDN/ALB/API); Network Firewall on VPC traffic paths (inspection VPC).

Q. MNC: design defense in depth for a public web app.

Edge WAF+Shield, Network Firewall or NGFW egress, SG tiers, host FW on bastion, app auth. Link our WAF/Shield chapters.

Q. Host-based vs network-based trade-off?

Host = precise per machine; Network = central policy for many hosts. Use both.

31. Tips in English, Marathi and Hindi

Ravindra Bagale's Tip (EN)

Name the layer before you name the product. Packet, stateful, proxy, NGFW, WAF — then pick AWS or vendor.

Ravindra Bagale's Tip (MR)

आधी layer नाव, मग product. Packet/stateful/proxy/NGFW/WAF — नंतर AWS किंवा vendor.

Tip (HI)

पहले परत का नाम, फिर प्रोडक्ट। Layer clear हो तो SG, NACL, WAF, Network Firewall भ्रमित नहीं करते।

Try at home

  1. Draw the vertical diagram for your company's public site.
  2. Tick which types you already own; star the gaps.
  3. Read the linked SG vs NACL chapter once end-to-end.

In short

  1. Firewall = policy point for allow/deny/inspect.
  2. Types: packet, stateful, proxy, circuit, NGFW, WAF, UTM.
  3. Host vs network; hardware vs software vs cloud.
  4. Link existing SG/NACL, WAF, Shield chapters — do not duplicate.

Revision, interview and comparison cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: Firewall types at a glance. Without names for layers you buy the wrong box. Packet, stateful, proxy/app, circuit, NGFW, WAF — plus host vs network and HW/SW/cloud/UTM. Guard story → vertical diagram → pick the layer → pick the product. Meera Kulkarni maps clinic edge to WAF and VPC path to Network Firewall.
Revision card: Firewall types at a glance · Download PNG · Open card page
Revision card: Host vs network firewall. One layer alone leaves gaps peers can abuse. Host = OS tools (iptables/nft/firewalld/ufw); Network = path for many hosts (SG, NF, NGFW). Bastion keeps host FW even inside a tight SG; tiers use network FW. Omar Haddad locks SSH on the bastion with ufw and SG together.
Revision card: Host vs network firewall · Download PNG · Open card page
Comparison: Packet-filter vs Stateful inspection. Packet-filter: Each packet alone; no table. Stateful inspection: Tracks connections; return traffic easier.
Comparison: Packet-filter vs Stateful inspection · Download PNG · Open card page
Comparison: WAF vs NGFW. WAF: HTTP/HTTPS L7 rules at CDN/ALB/API. NGFW: App ID, IPS, users across many protocols.
Comparison: WAF vs NGFW · Download PNG · Open card page
Interview card: Explain FW with a guard. Non-engineer interview opener. ID check=packet; memory of visitors=stateful; open parcels=proxy/WAF; all-in-one booth=UTM/NGFW. Say where WAF sits vs network FW.
Interview card: Explain FW with a guard · Download PNG · Open card page
Interview card: Packet vs stateful?. Classic compare. Packet=each packet alone; stateful=connection table and return traffic. SG is stateful; NACL is closer to packet/stateless.
Interview card: Packet vs stateful? · Download PNG · Open card page
Interview card: Where does WAF fit?. Layer clarity. HTTP/HTTPS L7 on CF/ALB/API — not a replacement for SG or host FW. Link the WAF/Shield chapters for depth.
Interview card: Where does WAF fit? · Download PNG · Open card page
Interview card: When is UTM enough?. Buy decision. Small sites wanting one appliance; grow to best-of-breed as scale/risk grows. Patches still required or signatures rot.
Interview card: When is UTM enough? · Download PNG · Open card page

More cards: Ravi Sir's Cards.

Practice Tasks

About this scenario

Maple Leaf Books is a bookselling business in Toronto. Emily Tremblay looks after its IT and cloud work. They count money in CAD and run their AWS resources in the ca-central-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 16

Easy Packet filter is mostly stateless — 1

Why: Basics.

What to do: Enter 1 if packet-filter FWs decide mostly per-packet without connection memory.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Stateful tracks connections — 1

Why: Memory.

What to do: Enter 1 if stateful inspection tracks active connections.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy WAF is Layer 7 HTTP — 1

Why: HTTP.

What to do: Enter 1 if a WAF focuses on HTTP/HTTPS Layer 7.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy UTM is unified appliance idea — 1

Why: Bundle.

What to do: Enter 1 if UTM means Unified Threat Management.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy List three FW type names

Why: Recall.

What to do: Write a YAML list key types with three strings: packet-filter, stateful, waf.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Easy Hardware FW is an appliance — 1

Why: Form.

What to do: Enter 1 if hardware firewalls are typically dedicated appliances.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Software FW is installed on a host — 1

Why: Form.

What to do: Enter 1 if software firewalls install on a general-purpose host OS.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Host FW runs on the OS — 1

Why: Where.

What to do: Enter 1 if host-based firewalls run on the endpoint OS.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Network FW sits on the path — 1

Why: Path.

What to do: Enter 1 if network-based FWs sit on the traffic path for many hosts.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium NGFW adds app ID / IPS — 1

Why: Next-gen.

What to do: Enter 1 if NGFWs add app identity and IPS-style features beyond classic stateful.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Proxy inspects application content — 1

Why: Middlebox.

What to do: Enter 1 if application/proxy FWs inspect application content via a middlebox.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Map layer labels

Why: Labels.

What to do: YAML: packet: L3-L4, waf: L7.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Hard Security Group is a cloud FW — 1

Why: AWS.

What to do: Enter 1 if an AWS Security Group is a managed stateful virtual firewall for ENIs.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Circuit-level is session-oriented — 1

Why: Session.

What to do: Enter 1 if circuit-level gateways validate sessions more than deep payloads.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Cloud FW is delivered as a service — 1

Why: Model.

What to do: Enter 1 if cloud firewalls are delivered as managed cloud services.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Defense in depth uses multiple layers — 1

Why: Layers.

What to do: Enter 1 if edge WAF plus network FW plus host FW is defense in depth.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.