Firewalls control which systems can communicate and under what conditions. This guide explains why they are needed, how their inspection methods differ, and what happens to packets as they move through stateful filtering, policy evaluation and NAT.
What is a firewall?
A firewall is a security control that regulates network communication according to defined rules. Those rules determine which traffic can cross a network or host boundary, what should be denied, and whether some traffic requires additional inspection. The control may be a dedicated appliance, an operating-system feature, a virtual machine or a managed cloud service.
A firewall’s main function is access enforcement. It does not automatically know whether an authorized application is secure or whether permitted traffic contains malicious activity. The protection it provides depends on where it is placed, which traffic reaches it, how much of that traffic it can examine and how its policy is configured. NIST describes both network and host firewalls as controls for traffic between systems with different security requirements. Its firewall guidelines remain a useful foundation, although the 2009 publication should not be used to establish modern product capabilities.
Why are firewalls needed?
An IP route answers whether one system has a path toward another. It does not answer whether that communication should be allowed. A firewall enforces the second decision.
Consider a network containing public web servers, application services, databases and employee workstations. A web server may need to accept HTTPS requests from the internet. A database generally should accept connections only from approved application services. Employees may need outbound access to selected services without allowing arbitrary inbound connections to their devices. All three requirements are about communication boundaries, but each needs a different policy.
Firewalls help reduce unnecessary exposure, constrain traffic between security zones, regulate outbound connections and establish explicit permitted paths. Internal firewalls and host controls are valuable because an external perimeter does not protect all east-west communication between systems. Filtering can also reduce the paths available to an attacker after one workload is compromised, but it cannot replace application authorization, endpoint protection, patching, authentication or monitoring.
A firewall can enforce only what it can see. Traffic routed around it, traffic carried inside an opaque tunnel, or application content hidden by encryption may fall outside the enforcement decision unless the deployment includes suitable controls. This visibility boundary is a design constraint rather than an unusual edge case.
How does a firewall work?
The basic operation is to identify relevant traffic, evaluate the applicable policy and apply a verdict. Depending on the technology, that evaluation can use packet headers, flow history, user or workload identity, application metadata and sometimes inspected application content.
A conventional network firewall policy can match the source and destination IP addresses, protocol, source or destination port, input or output interface, security zone, traffic direction and connection state. It may permit a packet, silently drop it, reject it with a protocol response, log the decision or send traffic to another inspection stage. Support for these actions and their order is product-specific.
A packet permitted by a firewall is not guaranteed to reach the application. Routing must still succeed, other enforcement points may act later, and the destination service must be listening and willing to accept the connection. Conversely, an established route does not override a firewall denial.
Where firewall inspection fits in the protocol stack
The common OSI layer labels are useful shorthand, but a modern firewall often examines several layers at once. The more practical distinction is what information the inspection engine actually has.
| Information available | Examples | Typical security decision |
|---|---|---|
| IP and network metadata | Source/destination IP, protocol number, interfaces | Permit or deny traffic between networks |
| Transport information | TCP/UDP ports, TCP flags, flow direction | Allow particular services and connection behavior |
| Connection context | Previously observed packets, reply direction, timeouts | Permit replies associated with an allowed flow |
| Application information | HTTP method, path, headers, application identity when visible | Apply application-specific restrictions |
For encrypted traffic, a network firewall may see IP addresses, ports and some connection metadata without seeing the HTTP request body. Inspection of encrypted application contents requires an appropriate termination or decryption arrangement, and that carries operational and privacy implications. Detailed WAF and secure web gateway inspection belongs to later articles.
What types of firewalls exist?
There is no single authoritative number because the term type can describe an inspection method, an enforcement location, a deployment model or a specialized purpose. The categories overlap.
| Classification | Examples | What it describes |
|---|---|---|
| Inspection method | Stateless packet filter, stateful inspection, proxy, application-aware inspection, next-generation firewall functions | What information informs the verdict |
| Placement | Network perimeter, internal segment, individual host, application edge | Where policy applies |
| Delivery | Physical appliance, host software, virtual appliance, managed cloud service | How enforcement is deployed and operated |
| Specialization | Network firewall, web application firewall, DNS/web filtering, workload segmentation | Which communication or security problem is addressed |
A physical appliance may combine stateful inspection, IPS and application identification. A managed cloud firewall can enforce network policies without exposing a traditional appliance. A web application firewall inspects HTTP-layer activity and is not a replacement for network-layer policy. An ordinary Linux host may perform firewall enforcement with software alone.
This is Article 1 of an eight-part Firewall Ecosystem series. Eight describes the planned articles, not eight mutually exclusive firewall types. The later articles cover physical/NGFW products, free and commercial platforms, cloud and virtual firewalls, WAF/API protection, DNS and web filtering, microsegmentation, and enterprise design and operations. Here we establish the mechanisms shared across those subjects.
Where firewall policy is enforced
Firewall placement determines which communication crosses a rule boundary. One deployment may require multiple complementary controls.
Accessible text alternative for this figure
Traffic from the Internet (untrusted sources) reaches a perimeter firewall with inbound and outbound policy, then the application environment of web and application services.
Between the application environment and the private data services sits internal segmentation, which applies application-to-database policy.
Host firewall policies can also run on individual workloads. The diagram is conceptual and not a universal topology.
This is a conceptual placement diagram. It is not a universal traffic topology. Some environments use distributed host-based rules instead of a centralized internal firewall, and cloud firewalls may enforce policy within the provider’s network rather than at a single routed box. The essential architectural question is which traffic flows cross each control.
Packet filtering: from packet fields to a rule decision
A packet filter evaluates fields of each packet against a policy. In a simple ruleset, a rule might allow TCP connections toward an application service on port 443 while denying unrelated new connections. Source and destination addresses identify the endpoints, while the protocol and destination port identify the service being requested.
But an address-and-port match does not necessarily identify the application. TCP port 443 usually indicates HTTPS, yet the port number by itself does not prove what protocol or content is running there. A rule accepting a port is therefore narrower than a claim that the application is understood and safe.
A useful way to read a network rule is as a set of conditions and an outcome:
| Policy component | Example | Engineering significance |
|---|---|---|
| Source | Application subnet | Who may initiate or originate traffic |
| Destination | Database service address | Which system is protected |
| Protocol/service | TCP destination port 5432 | Which network service is permitted |
| Direction/zone | Application zone to database zone | Which trust boundary is crossed |
| Connection context | New or established | Whether the policy distinguishes initiation from replies |
| Action | Allow, drop or reject | What happens when the rule applies |
| Logging | Selected matches or denies | Whether the decision can be investigated |
An illustrative rule allowing an application subnet to reach a database is not permission for every service between those networks. A precise rule should restrict both endpoints and service. A real policy may also require source identity, time limits and explicit controls around changes.
Rule ordering, default behavior and shadowing
Firewalls do not share one universal rule algorithm. Some evaluate the first matching rule, some combine layered policies, and others consult multiple processing stages. A broad rule can shadow a more specific rule if the broad rule takes precedence, making the specific rule ineffective. Default-deny design means traffic without an applicable authorization should not be allowed merely because no explicit deny was written. The exact default and where it applies must be established for each product.
Rules that look correct in a user interface may not describe the complete effective policy. Interface rules, security groups, route selection, inherited policy and inspection engines can all affect outcomes. The remainder of this article uses Linux Netfilter to show one precise implementation rather than claim that all firewalls execute rules in the same order.
Stateful inspection: why flow history matters
A stateless filter makes each packet decision without requiring a remembered exchange. For a TCP connection, this means rules must account for the packets in both directions using packet attributes or other means. A stateful firewall can maintain a flow record and use that record to recognize subsequent packets and return traffic.
For TCP and UDP, the familiar five-tuple consists of the source IP address, source port, destination IP address, destination port and transport protocol. Connection tracking also retains original and reply directions, protocol-specific state and expiration information. The five-tuple is a useful explanation of flow identity, not a claim that every protocol uses transport ports. ICMP, for example, has a different structure.
TCP endpoint state is not firewall connection state
TCP has its own state machine. The endpoints use SYN, SYN-ACK and ACK to establish a conventional connection. The TCP specification also describes closing states such as FIN-WAIT-1, CLOSE-WAIT and TIME-WAIT. A firewall watching these packets maintains a separate tracking view.
Accessible text alternative for this figure
A client and a server exchange SYN, SYN-ACK, ACK and then data, and every packet passes through a firewall.
The firewall keeps its own view of the flow, which moves from new to established. That classification is implementation-dependent and is not the same as the TCP endpoint states.
The firewall may classify the early flow as new and later valid bidirectional traffic as established. These connection-tracking terms do not map one-for-one to TCP endpoint states. Whether a particular packet matches a given conntrack state depends on observed traffic, tracking configuration and protocol validation. RFC 9293 defines the TCP endpoint state machine. The nftables conntrack reference documents the separate firewall-facing labels.
| Conntrack state | Meaning in Netfilter policy |
|---|---|
new | A valid initialization or early flow packet without a recognized two-way established exchange |
established | Traffic associated with a recognized bidirectional flow |
related | A separate flow or control message associated with an existing tracked communication |
invalid | Packet that cannot be properly associated with valid expected tracking behavior |
untracked | Packet intentionally excluded from normal connection tracking |
These are classification concepts, not a universally safe rule to accept or drop everything with a particular label. For instance, a production firewall policy must consider required ICMP error handling as well as TCP/UDP sessions.
UDP and ICMP cannot be treated like TCP
UDP does not establish a transport connection with a SYN handshake. Stateful firewalls instead associate datagrams with a flow key, remember their directions and expire tracking entries after configured idle periods. A reply may match an existing record even though neither endpoint negotiated a connection. The absence of a UDP reply is not proof that the first datagram was blocked.
ICMP and ICMPv6 contain both diagnostic and network-control messages. Error reports may carry information from the original offending packet, which allows an implementation to associate an error with another tracked communication. Overly broad ICMP filtering can impair error reporting and, in IPv6, essential network operation. IPv6 requires particularly careful handling of Neighbor Discovery and Packet Too Big behavior. See RFC 792 for foundational ICMP semantics, RFC 4443 for ICMPv6 messages and RFC 4861 for Neighbor Discovery.
Linux Netfilter: how the packet path is implemented
Netfilter exposes processing hooks in the Linux networking stack. nftables attaches base chains to selected hooks to evaluate packet matches and verdicts. It is a powerful reference implementation, but its detailed hook and priority rules are Linux-specific.
Accessible text alternative for this figure
Network ingress passes PREROUTING and then a routing decision. Local traffic goes to INPUT and the local application. Transit traffic goes to FORWARD and then POSTROUTING.
Locally generated traffic follows OUTPUT, then POSTROUTING, then egress. Bridging, ingress and offload details are omitted.
These are the normal routed packet paths and omit lower-level ingress processing, bridging, tunneling, flow offload and other implementation details. The route lookup determines whether traffic is delivered locally or forwarded. Correct rules for input do not automatically permit traffic on forward. A host-generated packet follows output, not the external ingress path.
A base chain declares its family, type, hook, priority and optional default policy. Family determines the packet/address context, while priority determines evaluation order among operations at a hook. The Netfilter hooks documentation and nftables manual give the implementation-specific details.
Why an earlier allow can still be followed by a drop
This documentation-derived example has two base chains attached to the input hook at different priorities:
table inet demonstration {
chain early {
type filter hook input priority 0; policy accept;
tcp dport 443 accept
}
chain later {
type filter hook input priority 10; policy drop;
}
}
Traffic to TCP port 443 can match accept in the first chain and still be dropped by the later chain. The nftables accept verdict does not override all later base chains at the same hook. A drop verdict terminates processing. If two base chains share the same hook and priority, their order should not be assumed. The nftables manual documents these semantics.
This example illustrates rule evaluation only. It is not a safe production ruleset. Applying it to a real host could deny access. It has not been executed in an isolated lab.
A stateful filtering rule fragment
ct state established,related accept
ct state invalid drop
These expressions show how a Netfilter policy can distinguish tracked reply/related traffic from packets classified as invalid. They are fragments rather than a deployable configuration. A complete policy still needs explicit requirements for new flows, local services, IPv6 control traffic, hook registration, rule order, default actions and safe management access.
Network Address Translation is separate from firewall authorization
NAT changes packet addressing. Destination NAT (DNAT) rewrites a destination address or port, commonly to direct incoming traffic toward an internal service. Source NAT (SNAT) rewrites a source address or port, commonly when traffic exits toward another network. Address translation does not itself decide whether the connection is authorized.
A simplified example shows how an inbound destination translation changes the packet as it moves toward a private server:
| Stage | Source IP:port | Destination IP:port |
|---|---|---|
| Before DNAT | 192.0.2.10:51000 | 203.0.113.5:443 |
| After DNAT | 192.0.2.10:51000 | 10.10.20.5:443 |
| Reply before reverse translation | 10.10.20.5:443 | 192.0.2.10:51000 |
| Reply after reverse translation | 203.0.113.5:443 | 192.0.2.10:51000 |
The addresses are illustrative, including documentation address ranges. The table assumes a valid route, a working stateful translation and permitted return traffic. It does not claim observed packet captures or an Internet-routable lab.
Accessible text alternative for this figure
Before destination NAT the connection runs from 192.0.2.10 port 51000 to 203.0.113.5 port 443. After DNAT the destination is 10.10.20.5 port 443.
The reply from the internal service, from 10.10.20.5 port 443 to 192.0.2.10 port 51000, is reverse translated so that it appears to come from 203.0.113.5 port 443. The addresses are illustrative, not a measured capture.
For common routed Linux configurations, DNAT at prerouting occurs before the main forwarding route decision, while SNAT at postrouting occurs after routing. The stage matters because filtering rules may see a translated destination rather than the original one.
In nftables stateful NAT, the first packet of a flow evaluates translation rules and establishes a binding. Follow-up packets use the existing binding without repeating NAT-rule lookup for each packet. The nftables NAT documentation explains the mechanism and a compatibility requirement for kernels earlier than 4.18. Changing a NAT rule also does not necessarily replace the translation binding of a flow already being tracked.
A firewall rule that permits a translated connection still requires correct routing and return-path handling. NAT is not a substitute for filtering, and filtering does not guarantee the destination application is functioning.
Operational limits: state capacity, asymmetry and visibility
Tracking flow state consumes resources. Linux exposes the current number of connection-tracking entries through nf_conntrack_count and the configured limit through nf_conntrack_max. Protocol-specific timeouts influence how long inactive entries remain. An implementation under excessive connection churn may have different failure behavior from one handling long-lived established flows.
Asymmetric traffic paths create another problem. If a stateful firewall observes packets in one direction but the replies bypass the same enforcement point, the firewall may not have the bidirectional history required by its policy. The exact outcome depends on how the implementation treats the traffic, where state is maintained and whether state is synchronized between devices.
Logging is similarly bounded. A log record can establish that a given processing stage rejected a packet. It cannot prove that every preceding or subsequent network element treated the traffic the same way. Packet captures require careful placement and interpretation, especially when NAT or offload changes what appears at an interface.
An IPv4-only policy also says little about IPv6 enforcement. When IPv6 is enabled, engineers must confirm both address-family coverage and required ICMPv6 behavior rather than treating IPv6 as an afterthought.
Implementation reference: inspect before changing policy
For a Linux system already using nftables and connection tracking, these are useful read-only inspections:
# Interfaces and addresses
ip -br address
# Main IPv4 route table
ip -4 route show
# Full ruleset with rule handles
sudo nft -a list ruleset
# Current tracked flow count and configured limit
sysctl net.netfilter.nf_conntrack_count
sysctl net.netfilter.nf_conntrack_max
# Current tracked connections (requires conntrack-tools)
sudo conntrack -L
These commands are illustrative, have not been run in a test environment and may require privileges or installed packages. For IPv6, inspect ip -6 route show separately. To establish which rule produced a verdict, nftables supports nftrace with nft monitor trace. Enabling targeted trace rules changes firewall configuration, so such testing belongs in a disposable or explicitly authorized lab. See the nftables tracing guide.
Detailed packet-capture analysis, HA troubleshooting, migrations and incident operations are intentionally reserved for Article 8. Here the implementation example has one purpose: to connect the general concepts to a real, inspectable packet-filtering engine.
What matters when evaluating firewall policy
A firewall decision depends on which traffic reaches the enforcement point, which fields or flow context it can inspect, and which rules apply. Routing and address translation can change the path and packet information seen at different stages. Understanding these relationships is essential when diagnosing unexpected access or designing rules that permit only the intended communication.
References and further reading
- NIST SP 800-41 Rev. 1, Guidelines on Firewalls and Firewall Policy, 2009, foundational rather than current product guidance
- RFC 9293, Transmission Control Protocol
- RFC 792, Internet Control Message Protocol
- RFC 4443, ICMPv6 Specification
- RFC 4861, Neighbor Discovery for IPv6
- Netfilter hooks
- nftables conntrack metadata
- nftables manual
- nftables NAT
- Linux kernel conntrack sysctl reference
- nftables packet tracing
