Linux netfilter
How a Linux firewall sees a packet
When a computer receives network data, it arrives in packets. Linux must decide whether a packet is for a program on this machine, should be sent onward, or should be dropped. Netfilter is part of the Linux kernel, the core of the operating system. It provides checkpoints, called hooks, where networking components can inspect or change packets. Firewalls, address translation, connection tracking, and logging use these checkpoints.
If your account is allowed to use sudo to run a command with elevated privileges, list the rules loaded in your current network view with:
sudo nft list ruleset
sudo nft list hooks inet
nftables is the Linux rule system built on Netfilter; nft is its command-line tool. The first command lists installed rules. The second lists hooks for the inet address family, which covers both IPv4 and IPv6; it needs a sufficiently recent nftables and kernel version with hook-listing support. A network namespace is a separate network view, such as the one used by a container; the output shows only rules active in the current namespace.
Follow a packet through the rules
The packet's route depends on where it came from and where it is going. Traffic arriving from a network interface typically passes the prerouting hook, a checkpoint before the system chooses where to send it. A packet for the local machine reaches input; one routed through the machine reaches forward. Traffic created by a local application follows output, then postrouting before it leaves.
NAT, or network address translation, changes network addresses or ports at particular hooks. Connection tracking remembers packets that belong to the same network flow. These operations affect which rules apply and what endpoints see.
Nftables is the modern packet-classification rule system built on Netfilter. A table groups chains for an address family such as inet, which covers IPv4 and IPv6. A base chain attaches to a hook and has a type and priority. Its rules can check a protocol, address, port, interface, or connection state, then return a verdict such as accept, drop, reject, or jump to another chain. A regular chain organizes reusable rules but does not attach to a hook by itself. Older iptables commands may use legacy or compatibility back ends, depending on the distribution and configuration.
Test before changing a policy
This small nftables table attaches a filtering chain to input and accepts traffic by default:
table inet demo {
chain input {
type filter hook input priority filter;
policy accept;
}
}
Changing that policy to drop can cut off remote access if allow rules are missing. nft -c -f file.nft checks syntax and validation, but cannot prove that a change will preserve connectivity. Keep a recovery path available and know which service loads saved rules before applying a firewall change.
Other software may install rules, including a network manager, firewall service, container runtime, or local configuration tool. To investigate one packet, identify its direction and hook path, inspect the relevant chain and policy, then check whether NAT or connection tracking changes the result. A ruleset listing alone is not a full security assessment; routing, interfaces, network namespaces, and rules managed elsewhere also matter.




