Firewalls
Firewalls enforce rules about which traffic may pass between networks or reach applications. This lesson covers firewall types, architectures and rule management.
Learning outcomes
After completing this lesson, you will be able to:
- Compare firewall types, including NGFWs and WAFs.
- Explain screened subnets and firewall rule management.
Firewall types
Firewalls have evolved through several generations, each inspecting more of the traffic. The following table compares them.
| Type | Inspects | Notes |
|---|---|---|
| Packet filter | Headers: addresses, ports, protocol | Stateless and fast; easily evaded by fragmentation and spoofing |
| Stateful | Connection state plus headers | Allows return traffic for established sessions automatically |
| Application-level (proxy) | Application content | Terminates and re-creates connections; slower but thorough |
| Next-generation (NGFW) | Applications, users, content, threats | Adds application identification, user identity, IPS, TLS inspection and threat intelligence |
| Web application firewall (WAF) | HTTP requests and responses | Protects web applications from injection, cross-site scripting and similar attacks |
Network firewalls protect network boundaries and segments; host-based firewalls protect individual systems; cloud environments provide security groups and firewall services.
The difference between stateless and stateful filtering is easiest to see with return traffic. When an internal user browses a website, the request leaves from a random high port to port 443, and the reply comes back to that high port. A stateless packet filter must allow inbound traffic to the whole range of high ports to let replies through, which also lets attackers send unsolicited traffic to those ports. A stateful firewall records the outbound connection in its state table and allows only the matching replies, so unsolicited inbound traffic is still blocked.
Next-generation firewalls add context that port numbers no longer provide. Many applications now use port 443, so a rule that allows HTTPS allows file sharing, remote access tools and malware command channels alike. An NGFW identifies the actual application and the user behind the connection, so a rule can allow the company's approved file-sharing service for the marketing group while blocking other file-sharing services for everyone, which a port-based rule cannot express.
Choosing a firewall type
Architectures and rule management
A screened subnet (DMZ) places public-facing servers in a network between the internet and the internal network, separated by firewalls, so that a compromised public server does not give direct access to internal systems. Designs use two firewalls or one three-legged firewall, and bastion hosts are hardened systems exposed to untrusted networks.
Rule sets follow default deny (implicit deny): everything not explicitly allowed is blocked. Rules are ordered from most specific to most general, because firewalls usually apply the first match; each rule has a documented business justification and owner; and rule sets are reviewed regularly to remove unused, redundant or overly broad rules. Changes go through change management.
Traffic paths through a screened subnet follow a consistent pattern. The external firewall allows internet users to reach only the specific public services in the DMZ, such as HTTPS on the web servers. The internal firewall allows the web servers to reach only the specific internal services they need, such as one application server port, and allows no connection from the internet to the internal network at all. If a web server is compromised, the attacker is confined to the DMZ and whatever narrow paths the internal firewall permits.
Rule reviews look for specific problems: rules that have not matched any traffic for months, rules shadowed by an earlier broader rule so they never take effect, rules using "any" for source, destination or service, and rules whose owner has left. Firewall management tools report hit counts for each rule, which makes unused rules easy to find.
The following diagram compares a wrong and a correct rule order.

Rule review findings
Rule order
A firewall's first rule allows all traffic from the internal network to any destination. A later rule blocks internal hosts from reaching a known malicious IP range. Why does the block not work?
The firewall applies the first matching rule, so the broad allow rule matches first and the block is never reached. The specific block rule must come before the general allow rule, and the broad allow rule itself should be replaced by egress rules that permit only needed traffic, in line with default deny.
What does default deny mean in a firewall rule set?
Show answer
Any traffic not explicitly allowed by a rule is blocked.
Exam Tips
Remember for the exam
- Default deny: block everything not explicitly allowed.
- Order rules from specific to general.
- A WAF protects web applications at layer 7.
- Public servers belong in a screened subnet.