Stateful firewalls
Why a firewall tracks connections
A stateful firewall can use information about a flow and earlier packets when deciding whether to allow later traffic. This lets a policy permit replies to an approved request without giving every external host permission to initiate new connections. The state table is an implementation data structure, not the application session itself. Consider an internal client at 192.0.2.10 contacting a web service at 198.51.100.20 over TCP. The following is an offline trace: the policy permits new outbound TCP 443 flows and matching return traffic while state remains valid.
Client 192.0.2.10:51000 -> Server 198.51.100.20:443 TCPSYN: permitted by outbound policySYN-ACK: matches tracked reply directionACK: permitted as part of tracked flowRecognize the reverse flow
The five-tuple contains source IP, source port, destination IP, destination port and transport protocol. In the no-NAT example, the reply reverses source and destination addresses and ports while keeping TCP. A reply from the same server to a different client port is not a matching reply for this entry. Merely seeing an ACK flag or source port 443 is not the same as a valid state match. Real tracking can also use zones, protocol validation, translation information and timers. A stateful firewall does not itself establish that the remote application or user is trusted.
Original: TCP 192.0.2.10:51000 -> 198.51.100.20:443Reply: TCP 198.51.100.20:443 -> 192.0.2.10:51000Connection tracking labels
In Linux Netfilter, nftables can match connection-tracking labels such as new, established, related and invalid. New indicates traffic associated with a connection that has not yet been seen in both directions; it is not synonymous with a TCP SYN. Established indicates tracked traffic seen in both directions; it does not mean TLS or application authentication is complete. Related covers a recognized association with another connection, for example some ICMP error messages. Invalid identifies traffic that cannot be associated with a valid tracked connection. Untracked is a separate possibility. The excerpt below shows a match expression only, not a complete ruleset. An accept in one nftables base chain does not override a later drop in another chain.
nftables expression (illustrative, not a command):ct state establishedTime limits and asymmetric routing
State entries expire or can be removed, and different protocols use different tracking logic. UDP has no TCP handshake, but a firewall may maintain temporary UDP flow records. Assume a paper model with a fixed 60-second lifetime from creation and no refresh. A matching reply at elapsed time 59 seconds is permitted by its state rule; at 60 seconds it is not. This lifetime is invented for practice, not a vendor default. Asymmetric routing may send a reply through another device without the required state, unless the architecture provides the necessary synchronization or policy. Inspect both paths, state counters and timeout assumptions; do not disable state validation to diagnose a real outage.
Toy lifetime: 60 sElapsed 59 s: matching state validElapsed 60 s: state expiredPractice: distinguish policy from reachability
A permitted client request leaves the firewall but no reply is seen. This does not prove that the firewall dropped anything: a service may be unavailable, the route may be missing, or a reply may follow another path. Predict the result of a matching reply after state expiry under the paper default-deny rule: it is denied unless a separate rule permits it. Next, combine state and rule matching into a policy for several network zones. Source: nftables manual; connection tracking state guide (search excerpt only).
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Stateful firewalls — knowledge check
Apply concepts to fictional firewall policy scenarios.
Which reply matches the tracked TCP flow 192.0.2.10:51000 to 198.51.100.20:443, assuming no NAT?
What does an established connection-tracking label not prove?
The toy state entry expires at 60 seconds. At age 60, what does its state rule do?
Can a firewall track a UDP exchange?
Why can asymmetric routing affect a stateful firewall decision?