Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

Linux Firewall

Direct answer

A Linux host firewall filters packets in the kernel's netfilter framework. Rules are written with nftables (modern), iptables (legacy, often a front end to nftables) or managed by firewalld (RHEL) or UFW (Ubuntu).

When to use this

Use it to restrict which services a host exposes, or when traffic is blocked unexpectedly.

First 30 seconds

1. Which tool? systemctl is-active firewalld ufw nftables.

2. Full ruleset: nft list ruleset.

3. Service listening? ss -tulpn.

4. Test from another host: nc -vz <host> <port>.

5. Change rules in the active tool and persist them.

Operational verification

packet arrives → netfilter hooks → rules in order → accept/drop → service receives it

Evidence · next step

For Firewall, continue with the first unproven Topic check: Record namespace, IPv4/IPv6 family, source/destination address and port, protocol, interfaces, direction and exact failing workload. If that boundary is healthy, advance to the adjacent check: Identify the authoritative manager/backend such as nftables, iptables-nft/legacy, UFW or firewalld before making changes. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.

Continue only after interpreting the current observation.
Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Key commandsudo nft list ruleset
Scope / prerequisiteUse it to restrict which services a host exposes, or when traffic is blocked unexpectedly.
Reference · 1
What next?3 suggested next steps
Child topics (this level)10
Catalog command links1
Evidence1
On this pageJump to a specific section
Linux command reference

Primary Commands

Configuration and operational commands for this Topic.

Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

workload/socket → namespace + route decision → netfilter hook/base chain priority → rule/set/state match → verdict → conntrack/NAT → next hook/interface or local socket → application response

Healthy evidence: the authoritative ruleset is known, the original tuple reaches the expected hook/rule/verdict, counters or trace align with capture, and the intended application flow succeeds without unintended exposure.

Step 2 Verification and output interpretation Verify boundary

Verification path. Inspect the active kernel ruleset and relevant counters, then generate one controlled flow with known 5-tuple and direction. Follow routing/namespace placement into the expected Netfilter hook, watch the matching rule/chain counter, inspect conntrack/NAT state when applicable, and verify reply traffic. A policy file on disk is secondary to the active ruleset. Logging can support evidence but may be rate-limited or absent and should not replace counters/capture.

Existing fast checks for this Topic. - Record namespace, IPv4/IPv6 family, source/destination address and port, protocol, interfaces, direction and exact failing workload.

  • Identify the authoritative manager/backend such as nftables, iptables-nft/legacy, UFW or firewalld before making changes.
  • Read the complete effective ruleset with base-chain hook, priority, policy, sets/maps and counters; correlate routing and conntrack where stateful/NAT behavior matters.
  • Reproduce once while capturing at the relevant interfaces/hooks, then make the smallest demonstrated policy change and repeat the original workload plus regression traffic.

Verification chain. workload/socket → namespace + route decision → netfilter hook/base chain priority → rule/set/state match → verdict → conntrack/NAT → next hook/interface or local socket → application response

Step 3 Commands Verify boundary
nft list ruleset
firewall-cmd --list-all
ufw status verbose
iptables -S
Step 4 Failure modes and next checks Narrow the fault

Suspicious evidence: multiple managers compete, the wrong namespace/backend is inspected, default policy or earlier-priority rules override assumptions, counters never move for the failing flow, or policy appears correct while the workload still fails.

It does not show behavior outside the captured namespace, family, five-tuple, interface/direction, manager/backend, ruleset generation, conntrack/NAT state, time window or application scope. Firewall evidence is resolved only when the original packet tuple is shown to traverse the intended namespace and policy path with the expected verdict and the original application transaction succeeds; loaded configuration or one matching rule alone is insufficient.

Next check: Continue from the first unproven firewall boundary: preserve the current ruleset/state, capture the exact packet path and rule verdict, change only the demonstrated cause through the authoritative manager, read back effective policy, then repeat the original workload and regression flows.

Step 5 Common mistakes Narrow the fault
  • Mixing iptables, nftables and firewalld rules on one host.
  • Changing rules remotely without a rollback timer.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Drill down

Subtopics

Go one level deeper into this subject.

Subtopic Netfilter

Netfilter is the Linux kernel packet-processing framework that exposes hook points such as PREROUTING, INPUT, FORWARD, OUTPUT and POSTROUTING and provides the underlying filtering, connection-tracking and NAT machinery used by nftables and iptables frontends.

Subtopic nftables

nftables is the modern Linux netfilter rule-management framework using tables, chains, rules, sets, maps and expressions across families such as inet, ip, ip6, bridge and netdev, with atomic ruleset transactions and explicit base-chain hooks/priorities.

Subtopic iptables

iptables is the classic netfilter rule interface organized around tables and built-in chains; modern distributions may implement the command through the nftables backend (`iptables-nft`) while others still expose legacy xtables semantics, so backend identity is part of every diagnosis.

Subtopic UFW

UFW (Uncomplicated Firewall) is a policy frontend that simplifies host firewall management while generating lower-level netfilter rules, including user, before/after and routed policy that may be implemented through nftables/iptables compatibility on the distribution.

Subtopic firewalld

firewalld is a dynamic Linux firewall manager that expresses policy through zones, services, ports, rich rules, source/interface bindings and policies while maintaining runtime and permanent configuration, typically using nftables as its backend.

Subtopic INPUT

INPUT is the netfilter path for packets that have completed an ingress routing decision and are destined for a local address/socket on the Linux host; it is not the chain for transit forwarding or ordinary locally generated output.

Subtopic OUTPUT

OUTPUT is the netfilter path for locally generated packets after a local process creates traffic and before final egress processing; it is distinct from forwarding and can evaluate locally known attributes, marks, destination state and post-routing/NAT behavior.

Subtopic FORWARD

FORWARD is the netfilter path for packets routed through the Linux host between interfaces or namespaces rather than delivered to or generated by a local socket, and it commonly intersects IP forwarding, bridges/routers, containers, VPNs and NAT gateways.

Subtopic NAT

Linux firewall NAT rewrites packet addresses and/or ports using netfilter state, commonly DNAT for destination publication and SNAT/MASQUERADE for source translation, with rule placement tied to prerouting/output/postrouting and conntrack tracking of the resulting flow.

Subtopic Firewall Troubleshooting

Firewall Troubleshooting is the Linux workflow for separating routing, namespace, manager/backend, rule-order, conntrack/NAT and application failures when a flow appears blocked or unexpectedly permitted, while preserving evidence before broad flush/disable changes destroy the failure boundary.

Key points

Use one management tool per host — mixing firewalld, UFW and hand-written rules leads to surprises. Find out which one is active, then read the full ruleset. Allow your SSH session before enabling a default-deny policy.

Key checks
  • nft list ruleset — all nftables rules
  • iptables -S; iptables -t nat -S — iptables rules (if used)
  • firewall-cmd --list-all — firewalld zone settings
  • ufw status verbose — UFW rules and defaults
  • ss -tulpn — which services listen
ReferenceWhat it is1 section · depth on demand

Core model

Pin the exact network namespace, address family, packet tuple, ingress/egress interface and direction first. Identify the active policy manager and backend, read the complete effective ruleset including base-chain hooks, priorities and default policies, then reproduce the original flow while correlating rule counters/logs, packet capture, conntrack/NAT state and socket/application behavior.

ReferenceImportant terms & boundaries5 sections · depth on demand

What this shows and what it does not

Firewall evidence is resolved only when the original packet tuple is shown to traverse the intended namespace and policy path with the expected verdict and the original application transaction succeeds; loaded configuration or one matching rule alone is insufficient.

In depth

Linux firewalling: one kernel framework, several front ends

Every Linux firewall tool ultimately programs the same kernel framework: netfilter. The nftables wiki describes its core hooks:

  • prerouting, input, forward, output and postrouting;
  • ingress and egress for the netdev family, attached to individual interfaces.

It also names three packet paths:

  • Local delivery: prerouting → input.
  • Forwarded traffic: prerouting → forward → postrouting.
  • Locally generated traffic: output → postrouting.

Tools and how they relate

ToolLayerTypical distribution
nftables (nft)The modern native interface to netfilterDebian, RHEL 8+, most current systems
iptablesThe classic interface; often iptables-nft translating to nftablesOlder systems, scripts, Docker
firewalldA zone-based manager on top of nftablesRHEL family, Fedora, SUSE
ufwA simple front endUbuntu
Kubernetes, DockerGenerate their own rulesContainer hosts

Use one manager per host

Mixing firewalld, ufw and hand-written nft or iptables rules on one host leads to rules overwriting each other at reloads. Choose one tool to own the ruleset. Container runtimes add their own chains, so check with nft list ruleset after they start.

Checking what's really active

QuestionCommand
Which tool manages the firewall?systemctl is-active firewalld ufw nftables
Complete active rulesetnft list ruleset
Legacy iptables rules present?iptables-legacy-save, iptables-save
Which backend does iptables use?iptables -V (shows nf_tables or legacy)
Which ports listen, and who's allowed?ss -tlnp together with the ruleset
host$ systemctl is-active firewalld ufw nftables 2>/dev/null
active
inactive
inactive
host$ iptables -V
iptables v1.8.10 (nf_tables)
host$ sudo nft list tables
table inet firewalld
table ip nat
table ip filter
host$ sudo nft list ruleset | grep -c rule
host$ sudo ss -tlnp | awk 'NR>1 {print $4, $6}'

Reading the example

firewalld is the active manager, and its table is inet firewalld. The extra ip nat and ip filter tables were created through iptables-nft, typically by Docker. Both sets of rules apply to every packet, which is why the complete nft list ruleset is the only reliable view of the firewall.

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

How it works at runtime

Firewall is part of Firewall. Linux Firewall is the host packet-policy reference for proving how traffic is accepted, dropped, rejected, translated or forwarded through the kernel netfilter path before an application or routed workload consumes it.

Runtime state ownership and mechanics. Linux packet filtering is implemented by Netfilter hooks across ingress, local input/output, forwarding and postrouting paths. nftables, iptables compatibility layers, firewalld and UFW are policy/configuration interfaces that can program overlapping kernel rulesets. Connection tracking and NAT add per-flow state; routing decisions and namespaces determine which hooks a packet traverses. Rule counters are therefore meaningful only in the correct family/table/chain/hook context.

Topic-specific state model. Linux Firewall is the host packet-policy reference for proving how traffic is accepted, dropped, rejected, translated or forwarded through the kernel netfilter path before an application or routed workload consumes it.

Technical metadata. Host/VM + network namespace, distribution/kernel, IPv4/IPv6 family, firewall manager/backend, table/family, base-chain hook/type/priority/policy, rule handle/order, sets/maps, interface, five-tuple, conntrack state/zone, NAT pre/post tuple, packet/rule counters, firewall logs/trace, route, socket/listener, ingress/egress capture and original application result.

Interpretation rule. - Firewall service active ≠ intended rules are loaded in the namespace carrying the traffic.

  • Ruleset present ≠ the original packet traverses or matches the expected chain/rule.
  • A packet accepted by one hook ≠ later routing, forwarding, NAT, socket or application boundaries succeed.
  • A rule counter increment ≠ end-to-end workload success; it shows only packets matched that rule in the observed scope.

Quick reference

Linux firewalling layers: netfilter in the kernel; nftables as the current rule engine (iptables commands on modern distros are an nft-backed compatibility layer); firewalld (RHEL/Fedora/SUSE) and UFW (Ubuntu) as management front ends.

nft list ruleset | head -50
iptables -V                      # 'nf_tables' = iptables-nft
firewall-cmd --state; ufw status verbose

Use one management tool per host; mixing firewalld, UFW and hand-written rules leads to rules being overwritten on reload. Docker and Kubernetes add their own chains.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Limits and how it fails

Primary failure point. Firewall evidence is resolved only when the original packet tuple is shown to traverse the intended namespace and policy path with the expected verdict and the original application transaction succeeds; loaded configuration or one matching rule alone is insufficient.

Model. An ACCEPT rule does not guarantee later hooks, routing, reverse-path policy or application listening will succeed. A DROP symptom can come from remote firewalls or security groups outside the host. iptables output may represent an nft backend rather than a separate legacy ruleset. NAT changes addresses/ports but does not create application reachability by itself. Keep local firewall, kernel route, socket ownership and remote policy as distinct boundaries.

ReferenceConfiguration & state1 section · depth on demand

Configuration, persistence and lifecycle

Configuration intent and lifecycle. Choose one authoritative policy manager and understand generated rules before mixing direct nft/iptables edits with firewalld/UFW. Keep default policy, zone/interface/source assignment, forwarding and NAT ownership explicit. Transactional nftables updates are preferable to partially applied sequences. Persist only through the manager that owns startup restore. Before remote changes, preserve management access and have an out-of-band or timed rollback plan when lockout risk exists.

Distribution/platform context. Firewall owns Linux host packet-policy behavior across netfilter frontends. Linux Networking owns addressing/routing/link state; applications own listener/protocol health; Security owns higher-level policy intent and hardening governance.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

Authoritative/upstream documentation reviewed for bounded claims in Firewall. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://wiki.nftables.org/wiki-nftables/index.php/Main_Page · confidence 94%
Technical changelog & impact

What changed and what may be affected

Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.

Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
linux firewallhost firewall linuxpacket filtering linuxlinux firewall troubleshooting
Embedded reference data

Quick lookup tables

Firewall operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for Firewall.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateLinux Firewall is the host packet-policy reference for proving how traffic is accepted, dropped, rejected, translated or forwarded through the kernel netfilter path before an application or routed workload consumes it.Establish exactly what this Topic owns before crossing into another subsystem.
Fast verificationPin exact namespace + five-tuple + interfaces/direction → prove route/listener prerequisites → identify manager/backend → snapshot full ruleset + hook priorities/default policies → reproduce with counters/trace + packet capture → correlate conntrack/NAT → change one demonstrated cause → read back effective state → repeat original workload + negative regression flow.Use the shortest evidence path first; a fast check is a boundary test, not blanket proof.
Verification chainworkload/socket → namespace + route decision → netfilter hook/base chain priority → rule/set/state match → verdict → conntrack/NAT → next hook/interface or local socket → application responseTrace requested/configured state through effective state to the observed workload result.
Failure boundaryFirewall proof closes only when the original packet tuple is shown to traverse the intended namespace and policy path with the expected verdict and the original application transaction succeeds; loaded configuration or one matching rule alone is insufficient.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated Linux firewall evidence can establish this proof path: workload/socket → namespace + route decision → netfilter hook/base chain priority → rule/set/state match → verdict → conntrack/NAT → next hook/interface or local socket → application responseUse this observation only for the specific claim it actually supports.
Evidence limitIt does not independently prove behavior outside the captured namespace, family, five-tuple, interface/direction, manager/backend, ruleset generation, conntrack/NAT state, time window or application scope. Firewall proof closes only when the original packet tuple is shown to traverse the intended namespace and policy path with the expected verdict and the original application transaction succeeds; loaded configuration or one matching rule alone is insufficient.Do not promote a local success signal into end-to-end or adjacent-dependency proof.
Next troubleshooting checkContinue from the first unproven firewall boundary: preserve the current ruleset/state, capture the exact packet path and rule verdict, change only the demonstrated cause through the authoritative manager, read back effective policy, then repeat the original workload and regression flows.Continue to the next unresolved boundary while preserving the original test condition.

Firewall · operational reference

Compact Linux state, persistence, verification and boundary reference for fast lookup.

Reference boundaryFirewall
Topic pathFirewall
Runtime stateLinux Firewall is the host packet-policy reference for proving how traffic is accepted, dropped, rejected, translated or forwarded through the kernel netfilter path before an application or routed workload consumes it.
Fast checks- Record namespace, IPv4/IPv6 family, source/destination address and port, protocol, interfaces, direction and exact failing workload. - Identify the authoritative manager/backend such as nftables, iptables-nft/legacy, UFW or firewalld before making changes. - Read the complete effective ruleset with base-chain hook, priority, policy, sets/maps and counters; correlate routing and conntrack where stateful/NAT behavior matters. - Reproduce once while capturing at the relevant interfaces/hooks, then make the smallest demonstrated policy change and repeat the original workload plus regression traffic.
Verification chainworkload/socket → namespace + route decision → netfilter hook/base chain priority → rule/set/state match → verdict → conntrack/NAT → next hook/interface or local socket → application response Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary.
Failure boundaryFirewall proof closes only when the original packet tuple is shown to traverse the intended namespace and policy path with the expected verdict and the original application transaction succeeds; loaded configuration or one matching rule alone is insufficient.
Persistence ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?