← Quick references

iptables and nftables: understand the firewall already in place

Inspect a Linux lab firewall, identify its backend, and map a packet's path before considering any rule changes.

Identify the host and the tools

Begin on a Linux lab machine you administer, with a simple inventory goal: explain the firewall that is already there. The commands here inspect configuration and counters. They do not add rules, flush tables, or change default policies.

Record the host, time, and whether you are inside a container or the host's network namespace. A listing from the wrong namespace can be perfectly accurate and still describe the wrong firewall. Administrative permission may be needed to read the rules; version checks normally do not require it.

iptables --version
nft --version

Distinguish the command from the backend

The name iptables does not always mean the legacy firewall backend. Its version output can identify legacy or nf_tables. The nft-backed compatibility tools accept iptables syntax while using the nftables kernel API, which explains why rules can appear through more than one tool.

Keep the backend name in your notes. Do not switch alternatives or migrate configuration while trying to understand the current behavior. Also identify the service that owns the rules, such as a firewall manager or container runtime; hand edits may otherwise be replaced later.

Read the existing rules and counters

Use the listing commands appropriate to the installed setup. For iptables, -S prints rule specifications, while -L -n -v presents numeric addresses and counters. The default table is filter; inspect nat separately when investigating address translation. Check IPv6 as well as IPv4.

For nftables, list ruleset shows the current rules and -a adds handles. Keep those handles as references to this snapshot, not permanent identifiers. A permissions error or missing tool is not an empty firewall.

sudo iptables -S
sudo iptables -L -n -v
sudo iptables -t nat -S
sudo ip6tables -S
sudo nft -a list ruleset

Trace one expected packet path

Choose a known connection, then identify whether its packets are addressed to this machine, generated locally, or forwarded through it. Find the applicable chain or nftables hook, follow matching conditions in order, and note jumps into other chains. Check the relevant policy when no terminating rule decides the outcome.

In nftables, chain names are chosen by the author; the hook identifies where a base chain attaches. An inet table can cover both IPv4 and IPv6. If several base chains share a hook, inspect their priorities and later verdicts before deciding that one accept rule explains everything.

Start with the packet's relationship to the host
TrafficTypical filtering hook
Addressed to the local machineinput
Created by the local machineoutput
Routed through the machineforward

Record the explanation and its limits

Counters show rule matches over their lifetime, not an application-level success rate. Compare two observations without resetting them, and record the elapsed time. With nftables, counters appear only where configured.

End with the likely path, matching rules, and unanswered questions. Include the backend, namespace, address family, and rule owner. Save any proposed changes for a separate review with recovery access available; this first exercise is complete when you can explain the current policy without changing it.