pk.org: Computer Security/Lecture Notes

Firewalls

Controlling Access to Networks, from Packet Filters to Zero Trust

Paul Krzyzanowski – 2026-11-19

TLS and VPNs protect traffic as it crosses untrusted networks, but they do not decide which traffic should be allowed to cross in the first place. Some of the traffic arriving from the outside is hostile, and some of the machines on the inside cannot be trusted either. A firewall is a system that sits at the boundary between networks and enforces a policy on the traffic that crosses it.

We begin with network address translation, which was created to conserve IP addresses but also blocks unsolicited traffic from the outside. We then follow firewalls through three generations, from stateless packet filters to systems that identify applications inside encrypted traffic. We end with the zero trust model, which abandons the assumption that anything inside the network can be trusted.

Network Address Translation (NAT)

The IP Address Shortage

An IPv4 address is 32 bits, which allows about 4 billion distinct addresses. That seemed inexhaustible in the 1980s, but it is far fewer than the number of devices connected to the Internet today.

The shortage is worse than the raw count suggests because addresses were handed out in large blocks. Rutgers owns the 128.6.0.0/16 network: every address whose top 16 bits are 128.6, which is enough for 65,536 globally addressable devices. Large companies of the 1980s received /8 blocks of over 16 million addresses each.

Most devices do not need a globally unique address. A desktop in an office initiates connections to servers, but systems on the public Internet do not need to initiate connections to it. Network Address Translation (NAT), standardized in 1994, builds on that observation. Devices within an organization use private IP addresses: reserved ranges that are never routed on the public Internet. In 1996, the IETF (Internet Engineering Task Force), the body that defines Internet protocols, set aside three ranges for private use:

How Translation Works

A NAT-enabled router maintains a translation table that maps internal address and port pairs to external address and port pairs.

When an internal host at 192.168.1.10 sends a packet from its port 5000 to an external web server, the router replaces the source address with its own public address and an unused port, say 68.36.210.55 port 4000, and records the mapping. When the response arrives addressed to 68.36.210.55 port 4000, the router looks up the mapping and forwards the packet to 192.168.1.10 port 5000.

The dominant form today is NAPT (Network Address and Port Translation), which rewrites port numbers as well as IP addresses. Rewriting ports lets thousands of internal hosts share a single public address.

Security Benefits of NAT

NAT was designed to conserve addresses, but it also blocks unsolicited inbound traffic.

Consider a home or small office network behind a NAT router. The laptops, printer, and thermostat all have private addresses, such as 192.168.1.10. An attacker scanning the Internet cannot probe any of them: the addresses are not routable, so a packet cannot be addressed to them from the outside. A scan of the router’s public address reaches only the router itself and whatever mappings exist at that moment. The devices behind the router cannot be probed directly.

Traffic from the outside reaches an internal device only through a translation entry, and the entries are created in two common ways:

  1. The internal device made an outbound connection. When a laptop connects to a web server, the router creates a translation entry, and the server’s responses flow back through that entry. The entry is temporary: the router removes it after the connection ends or after a period of inactivity.

  2. A fixed mapping was configured. Port forwarding tells the router to send all traffic arriving on a given port to a specific internal device. This is how a service, such as a game server, is deliberately made reachable from the Internet.

The router drops every other inbound packet, since it cannot tell where to deliver it.

Translation and filtering are separate functions. NAT translates addresses and ports, while firewall rules determine which traffic is allowed. Translation happens to block unsolicited inbound traffic, but it does not inspect the traffic it forwards, and it does not restrict outbound connections, so a compromised internal machine can still connect outward freely. Controlling traffic is a firewall’s job.

Firewalls

The name comes from building construction, where a firewall is a barrier that keeps a fire from spreading between sections of a building. The networking use dates to the late 1980s, when organizations first connected their internal networks to the Internet and found that every internal host was now reachable from anywhere in the world. In November 1988, the Morris worm spread to thousands of machines through network services that administrators had never thought of as entry points. Filtering traffic at the network boundary was the first response to guard against similar future attacks.

A firewall is the enforcement point for a network’s security policy. It is placed where traffic between networks must pass, typically at the border between an organization’s network and the Internet, and it decides which traffic may continue: what services outsiders may reach, which hosts may communicate, and what internal systems may send out. The firewall itself may be a dedicated appliance, software on a router, or a function of a host’s operating system.

Firewall designs differ in how much context they use for each decision. The earliest examined each packet in isolation. Later designs track entire connections, and current products parse the application data inside the traffic. These stages are commonly described as generations, and we examine them in order.

First-Generation Firewalls: Packet Filters

A packet filter, also called a screening router, examines each IP packet crossing a network boundary and decides whether to forward it or drop it. It makes the decision one packet at a time. It does not remember past packets, and it does not examine application data. Its job is to enforce a set of rules based on values in the packet headers:

Rules and Chains

Rules are organized into ordered lists, called chains on Linux systems and access control lists on many routers. (These are unrelated to the access control lists that filesystems attach to files.) Each rule has two parts: the criteria that select which packets it matches, and an action that says what to do with them. Most systems offer four actions:

A packet is tested against the rules in order. The first matching Accept, Drop, or Reject ends the evaluation, so rule order determines the policy: a rule that accepts all web traffic placed before a rule blocking a specific host makes the block unreachable. Linux exposes this design directly, since its iptables and newer nftables firewalls organize rules into exactly these chains.

The Basic Principle of Firewalling

Ingress filtering controls traffic entering a network, while egress filtering controls traffic leaving it.

The basic principle of firewalling is that all traffic crossing a security boundary must pass through the firewall that enforces the boundary’s access policy. The firewall permits required communication and blocks everything else, and the network is designed so that traffic cannot bypass it.

For ingress traffic, the starting rule is default deny: block everything, then allow only the specific traffic the organization intends to accept. The chain below enforces that policy for a small organization whose public services are a web server at 128.6.4.10 and a mail server at 128.6.4.20:

# Source Destination Protocol and port Action
1 10.0.0.0/8, 172.16.0.0/12, or 192.168.0.0/16 any any Drop
2 128.6.0.0/16 any any Drop
3 any 128.6.4.10 TCP ports 80, 443 Accept
4 any 128.6.4.20 TCP port 25 Accept
5 any any TCP with ACK set Accept
6 any any any Drop

Rules 1 and 2 drop packets whose source addresses could only be forged. Private addresses are never valid on the outside interface, and a packet arriving from the Internet cannot legitimately claim a source inside the organization’s own network. Rules 3 and 4 admit the public services: web traffic on the HTTP and HTTPS ports, and mail delivery on the SMTP port. Rule 6 is the default deny that catches everything else.

Rule 5 approximates return traffic. Internal hosts connect to servers everywhere, and the responses must be let back in. The SYN-ACK response and ordinary TCP data packets all carry the ACK flag, so accepting ACK-flagged packets roughly matches responses to connections that insiders initiated. The approximation is also the chain’s weakness: the filter does not know whether a connection exists, and an attacker can set the ACK flag on any packet it constructs.

Egress filtering is less common but increasingly important. Internal hosts are generally trusted, but a compromised internal host is not. Egress rules can prevent it from:

Second-Generation Firewalls: Stateful Packet Inspection

A packet filter examines each packet in isolation, but protocols like TCP are conversations. Stateful packet inspection (SPI) firewalls track those conversations and evaluate each packet based on where it falls within one. Check Point, an Israeli security company, introduced the approach commercially in its FireWall-1 product in 1994 and coined the term.

Why State Is Important

A TCP connection begins with the three-way handshake: SYN, SYN-ACK, ACK. Data should flow only after the handshake completes. A stateless filter cannot enforce this because it does not remember the earlier packets. A stateful firewall records the state of each connection and can enforce rules that refer to it:

The return-traffic rule replaces rule 5 of the packet filter chain. Instead of accepting any packet with the ACK flag set, the firewall accepts packets that match a connection in its state table, a test an attacker cannot pass by setting a flag.

Handling some protocols requires reading more than headers. SIP (Session Initiation Protocol), which sets up Voice over IP calls, uses one connection for call setup, typically on port 5060, but the voice and video packets then flow over separate connections whose ports are negotiated inside the setup messages. An application-aware firewall can inspect the SIP exchange, learn which ports the media will use, and temporarily permit those flows. This goes beyond connection tracking, since the firewall must parse the application payload, but stateful firewall products commonly include such helpers for SIP and for FTP, the 1970s file transfer protocol with the same two-connection structure.

Benefits of Stateful Inspection

Tracking state makes a firewall far more capable:

Security Zones and the DMZ

An organization rarely has just a trusted inside and an untrusted outside. It defines multiple security zones with different trust levels, and its firewalls enforce a policy for traffic between each pair of zones.

The DMZ

The name comes from the demilitarized zone separating North and South Korea: a buffer strip belonging fully to neither side. A network DMZ is a zone that sits between the untrusted Internet and the trusted internal network. Servers that must be reachable from the Internet, such as web, mail, and external DNS servers, are placed in the DMZ rather than on the internal network.

The firewall applies a different policy to each direction of traffic:

Internet → DMZ:
Allow only specific services (HTTP/HTTPS, SMTP) to specific servers
Internet → Internal:
Block everything. External hosts must never reach internal hosts directly
Internal → DMZ:
Allow specific connections, such as SSH for administering the servers
Internal → Internet:
Generally allow, so users can reach Internet services, possibly with restrictions on protocols or destinations
DMZ → Internal:
Strictly limit to what the servers require, such as the web server reaching one internal database on one port
DMZ → Internet:
Restrict to required services, such as the mail server connecting to other mail servers

The reasoning behind the strict DMZ rules is that these servers accept connections from the entire Internet, so they are the systems most likely to be compromised. Limiting what they can reach in the internal network limits what an attacker gains by compromising one. An attacker who takes over the web server should not be able to reach employee workstations, download attack tools, or move on to other systems.

A server placed in the DMZ should be configured as a bastion host, named after the fortified positions that project outward from a castle wall. It’s a system hardened for exposure that runs only the software its service requires, has only essential user accounts, and is monitored and audited more closely than ordinary systems.

Network Segmentation

The DMZ is one instance of network segmentation: dividing an organization’s infrastructure into separate networks, with firewalls enforcing policy between them. A segmented organization might operate:

Segmentation applies the Principle of Least Privilege to networks: each segment can reach only what its systems need. The benefits are:

Third-Generation Firewalls: Deep Packet Inspection

Packet filters and stateful firewalls read headers: addresses, ports, protocols, and connection state. Deep packet inspection (DPI) reads the application data inside the packets. Inspecting content enables controls that headers cannot support:

Examining packets one at a time has a limit: the content that needs inspection often spans several of them. A downloaded file, email attachment, or web page arrives split across many packets. A malware signature can straddle a packet boundary, with half in one packet and half in the next.

Content inspection systems therefore reassemble traffic. The firewall acquires the packets of a flow, rebuilds the larger data they form, such as a complete file or message, and inspects that, so a signature split across packets is still detected. It can also decode encoded content, such as base64 email attachments, before inspecting it. The term deep content inspection (DCI) is sometimes used for inspection that reconstructs complete files and messages this way. Reassembly and decoding consume memory and time, so they are applied selectively to traffic that first matches screening criteria.

Design Challenges with DPI

Content inspection faces two hard constraints.

First, it must run at network speed. A firewall must keep up with links that deliver millions of packets per second, so it can buffer only a limited amount of data and match against a limited set of signatures.

Second, most traffic is now encrypted. Without access to the plaintext, a firewall sees addresses, ports, traffic characteristics, and whatever handshake information is exposed. Reading HTTP requests, downloaded files, or message contents requires the plaintext itself.

Some organizations get it with TLS interception: the firewall performs an adversary-in-the-middle (AitM) interception on its own users, decrypting traffic, inspecting it, and re-encrypting it. This requires installing the firewall’s certificate authority on every client machine, since each client now receives the firewall’s certificate instead of the real server’s. A browser connecting to a bank sees the firewall’s certificate, and the end-to-end protection that TLS was designed to provide ends at the firewall.

The trend runs against inspection in another way as well. Hostname filtering depends on the server name that the client sends in plaintext at the start of the TLS handshake. Encrypted Client Hello, an extension to TLS 1.3 that is now being deployed, encrypts that name, removing it as a signal for hostname filtering.

Intrusion Detection and Prevention Systems

Firewalls enforce a policy about which traffic is allowed. Intrusion detection examines the traffic that is allowed for signs of attack.

An Intrusion Detection System (IDS) monitors network traffic and reports suspicious activity. It is passive: it observes and alerts, but it does not block anything. An Intrusion Prevention System (IPS) sits inline in the traffic path and drops the packets it identifies as malicious before they reach their destination. The two share their detection methods but differ in what they do with a detection.

The field is older than the products suggest. In 1987, Dorothy Denning, then at SRI International, a California research institute, published the model these systems still follow: describe expected behavior, flag deviations from it, and combine that with rules describing known misuse. Snort, an open-source network IDS released in 1998, brought the approach into wide use and is still deployed today.

Three approaches to detecting threats are used, separately or in combination.

1. Protocol-Based Detection

This approach verifies that traffic adheres to protocol specifications. For example:

Many attacks deliver malformed or unexpected input to a protocol implementation. Enforcing strict protocol correctness blocks those attacks without requiring knowledge of any specific exploit. Validation has a limit, though: an attack expressed in valid protocol messages passes every check. A correctly formed HTTP request can still contain an injection attack.

2. Signature-Based Detection

This approach maintains a database of known attack signatures: byte sequences or packet sequences characteristic of a specific attack. As with malware detection, these signatures are unrelated to digital signatures. When traffic matches a signature, an IPS blocks it and an IDS flags it.

The limitation is the same one we saw with malware signatures: detection requires a matching signature. New attacks that reuse recognized characteristics can still be caught, but an attack whose traffic does not match any rule passes undetected, so the database requires constant updates.

3. Anomaly-Based Detection

Instead of recognizing known attacks, anomaly-based systems first build a statistical baseline of normal activity and then flag deviations from it:

The challenge is separating malicious anomalies from legitimate change. New employees, new applications, and shifting usage can all trigger false positives.

Challenges with IDS/IPS

Real deployments face several problems:

Next-Generation Firewalls (NGFW)

The term Next-Generation Firewall (NGFW) refers to products that combine stateful inspection, deep packet inspection, and intrusion prevention in a single platform. The name began as a marketing label, but it describes a real shift: firewalls that identify and control applications rather than relying on ports and protocols. An NGFW typically provides:

The defining addition is application identification. Older firewalls assumed that the port number revealed the application: port 80 meant HTTP and port 25 meant SMTP. Today nearly every application uses HTTPS on port 443, so port numbers reveal almost nothing.

An NGFW cannot know which process on a host generated the traffic; only a host-based firewall can see that. Instead, it classifies the application from what is visible on the network:

For example, Zoom, Slack, Dropbox, and Teams all use HTTPS on port 443, but they differ in their signaling behavior, packet size distributions, and TLS metadata. An NGFW uses these clues to classify each application and apply a policy to it, such as allowing Zoom while blocking file uploads to personal cloud storage.

Application Proxies

An application proxy takes a different approach from everything above. Instead of deciding whether to forward packets to a service, the proxy becomes the service’s external interface: clients connect to the proxy, and the proxy connects to the real server. It terminates the client’s connection and opens a separate one to the server, which gives it complete control over both sides of the exchange. This design has several benefits:

Web proxies and email gateways are common examples. The drawbacks are that each protocol requires its own proxy and the proxy can become a performance bottleneck, since it does far more work per connection than a packet filter.

API Gateways

The proxy design has a modern descendant. Organizations now expose their functionality as web APIs that mobile apps, partners, and their own front ends call.

An API gateway is an application proxy specialized for this traffic. It is the single entry point for all API requests: it authenticates the caller, checks that the caller is authorized for the specific request, limits request rates, logs the request, and forwards it to whichever internal service handles it. The services behind the gateway never face external clients directly, just as servers behind a proxy never did.

Host-Based Firewalls

Network firewalls protect networks. A host-based firewall runs on an individual system and filters that system’s own traffic at the endpoint, including traffic that never crosses the perimeter, such as packets from other machines on the same internal network. Both Windows and macOS include one: Windows Defender Firewall has been enabled by default since Windows XP Service Pack 2 in 2004, while the macOS application firewall must be turned on by the user. Linux systems use the kernel’s nftables or iptables filtering.

Running on the host also makes capabilities possible that a network firewall cannot offer. The firewalls built into Windows and macOS integrate with the operating system’s network stack, so they see which program opened each connection and can enforce rules per application, allowing one program to accept incoming connections while refusing another. Many host firewalls can also adapt to location, applying stricter rules on a coffee shop’s WiFi than on an office network. These are implementation capabilities rather than properties of every host firewall.

Network and host-based firewalls protect against different failures, which is why organizations deploy both:

Host-based firewalls also depend on the user. A person who does not understand a permission dialog will often click Allow just to make the dialog go away.

Deperimeterization and Zero Trust

Traditional network security assumes a perimeter: a clear boundary with trusted systems inside and the untrusted Internet outside. Firewalls defend the boundary. Once a user or machine is inside, it is largely trusted. That assumption is failing.

The Disappearing Perimeter

Deperimeterization refers to the breakdown of that boundary. Several developments have erased it:

The assumption that being inside the network makes a system safe is wrong, and modern designs abandon it.

Zero Trust

In 2010, John Kindervag, an analyst at Forrester Research, a technology research firm, argued that the inside of a network should be trusted no more than the Internet, and that every request should be verified regardless of where it originates. He named the approach zero trust.

Google reached the same conclusion after Operation Aurora, a 2009 intrusion attributed to attackers in China who moved freely once inside Google’s network. Google rebuilt its internal security so that employee access depends on the user and the device rather than the network location, and published the design as BeyondCorp in 2014. In 2020, NIST, the U.S. National Institute of Standards and Technology, standardized the concepts in Special Publication 800-207.

The principle of zero trust is never trust, always verify: require authentication and authorization for every access to every resource, regardless of where the request originates. Verification is repeated rather than one-time, and it covers the device as well as the user. A request from a correctly logged-in user on an unpatched or unmanaged laptop can be refused.

Zero trust is also more than multi-factor authentication (MFA). MFA verifies identity, while zero trust also evaluates the device and the context against policy.

The NIST model grants access per session, to one resource at a time, by dynamic policy. The policy can weigh identity, device state (operating system version, installed software, company-managed or personal), location, time, and current threat level. All communication is secured regardless of network location, so a connection between two machines on the same internal network is encrypted and authenticated just like one crossing the Internet. The organization continuously monitors the security posture of its assets and uses what it learns to adjust policy.

Granting access per session does not mean a password prompt for every click, since recent authentication and single sign-on can satisfy a new request. Authentication establishes identity, and policy decides access to each resource. Being inside the network, or holding access to one resource, does not authorize access to another.

Microsegmentation

Network segmentation divided an organization into a handful of zones. Microsegmentation continues the division down to a much finer grain. Each application gets a segment of its own, and the division can go further still, down to the individual virtual machines or containers that make up an application.

Each workload gets a precisely defined communication policy. A compromised web server cannot reach another application’s database. A compromised workstation cannot scan the network around it. This is zero trust applied to the network itself: a workload cannot reach another just because both are inside, and an attacker who gains a foothold is confined to one small segment rather than a flat internal network.

Firewalls at this granularity cannot be boxes at the network edge, since there would need to be thousands of them. Microsegmentation is instead enforced in software, by filtering built into the hypervisor or container runtime of the systems hosting the workloads, with a central controller distributing policy. The filtering moves from the network edge into the virtualization layer.

Securing Traffic Between Services

Microsegmentation controls which workloads can exchange packets. Zero trust requires more: the workloads must authenticate each other and encrypt their traffic. Many modern applications are built as cooperating services, with one handling logins, another inventory, another payments. A single page load can trigger dozens of requests between services inside the data center. Those internal requests were traditionally sent unauthenticated and unencrypted, which is the implicit trust that zero trust eliminates.

The mechanism is mutual TLS, or mTLS. It’s standard TLS with one addition: both ends of the connection present certificates, so each service verifies which service it is talking to. TLS itself already encrypts the traffic.

Certificates for thousands of short-lived workloads cannot be managed by hand, so infrastructure verifies what each workload is and automatically issues it a short-lived certificate.

Rewriting every service to perform mutual TLS and enforce policy would be an enormous change. A service mesh avoids it.

One common mesh design places a small proxy next to each service instance and routes all of the service’s traffic through it. The proxy manages the service’s certificate, authenticates and encrypts connections with mTLS, and checks that each request is authorized. The services themselves are unchanged and exchange plain traffic with a proxy on the same machine.

The proxies make up the mesh’s data plane, the components that handle the traffic itself. A central service called the control plane supports them. It distributes the short-lived certificates the proxies use, manages the policies they enforce, and provides service discovery, which tells each proxy which service instances exist and where to reach them. The mesh moves these protections into infrastructure: its proxies authenticate the participating services, encrypt their traffic, and enforce the configured access policies.

Zero Trust Network Access

For people connecting from outside, the zero trust replacement for the VPN is Zero Trust Network Access (ZTNA). A traditional VPN authenticates a user once and then places the user’s device on the internal network. Routing and firewall rules can constrain what the device reaches, but VPN access is often broad. ZTNA places an intermediary service between the user and each application: after authenticating the user and checking the device, it connects the user to the specific application requested, without providing general network connectivity.

Access decisions weigh device posture alongside identity: whether the device is managed by the organization, whether its software is current, and whether it has been jailbroken. The overall shift is from network-centric to identity-centric security. The question is never whether an address is internal, but whether this authenticated user, on this verified device, may use this specific application for this purpose.

Challenges with Zero Trust

Zero trust is an architecture rather than a product, and adopting it is a long program rather than an installation. The obstacles are:

How the Parts Fit Together

A modern organization uses nearly all of these mechanisms at once. Consider a company with offices, a data center, and remote employees:

The layers back each other up. If one fails, others still stand. This is defense in depth: an attacker who gets in faces another boundary at every step, and monitoring at several layers raises the chance that the intrusion is noticed.

Conclusion

Firewalls began as routers with filtering rules and grew into systems that track connections, parse application protocols, identify applications inside encrypted traffic, and block attacks as they happen. Each generation responded to a limit of the last: stateless filters could not distinguish a response from an intrusion, stateful firewalls could not see content, and content inspection lost its view as traffic became encrypted.

The deeper change is in what we trust. The perimeter model trusted a location: inside the perimeter meant safe. Zero trust replaces location with verified identity: of users, of their devices, and of the services communicating inside a data center. None of these layers is sufficient alone, so effective network security stacks them, and when one fails, the damage is contained and the intrusion is noticed.