← All 167 books iptables, one rule per page
One rule per page

iptables, one rule per page

Twenty-eight lessons on what iptables is: a user-space utility that configures the IP packet filter rules of the Linux kernel firewall, built on the Netfilter hooks in the kernel; the law of one rule per page; the table and the chain as the two drawers, the five hooks and the packet path; a rule read left to right, matches first then the action, ACCEPT and DROP as the honest pair, the default policy, the honest listing with -L and -S; conntrack and the stateful rule, the --test rehearsal; saving the ruleset, line numbers, the open door, the flush that locks you out; the nat drawer, the successor nftables named honestly, masquerade, rate limiting; one host and one honest hour, the keeper rule, five lines one wall, teaching a friend in one sitting.


Steve Hodgkiss 7 lessons

One rule, understood, rehearsed and listed. That's the whole wall.

iptables, one rule per page

Twenty-eight lessons on what iptables is: a user-space utility that configures the IP packet filter rules of the Linux kernel firewall, built on the Netfilter hooks in the kernel; the law of one rule per page; the table and the chain as the two drawers, the five hooks and the packet path; a rule read left to right, matches first then the action, ACCEPT and DROP as the honest pair, the default policy, the honest listing with -L and -S; conntrack and the stateful rule, the --test rehearsal; saving the ruleset, line numbers, the open door, the flush that locks you out; the nat drawer, the successor nftables named honestly, masquerade, rate limiting; one host and one honest hour, the keeper rule, five lines one wall, teaching a friend in one sitting.


Set in Space Grotesk, Inter and JetBrains Mono (SIL Open Font License).

Every fact is as the official source states it, fetched and read during this build: the local man page excerpt and --version line of iptables v1.8.10 (nf_tables) on this machine, and the Wikipedia articles Iptables, Netfilter, Nftables, Firewall (computing), Stateful firewall, Network address translation, Network security policy, Internet Control Message Protocol, Port (computer networking) and Transmission Control Protocol. No facts come from Reddit, Stack Overflow, vendor blogs or commercial sites. Every iptables output quoted here was captured read-only on this machine (--version, -L and -S listings, or iptables-restore --test on a scratch file that loads nothing), cached verbatim beside this book.

Honest notes: the Wikipedia Firewall configuration article was a 404 at dispatch, and the Packet filtering article is a redirect stub; neither was used as a source. The -L listing's column header row is never quoted in these pages; every rule row quoted is verbatim. SAFETY LAW: no firewall rule was ever inserted, appended, deleted, replaced or flushed on this host for this book. Independent, not affiliated with the netfilter.org project or the Wikimedia Foundation.

Your purchase is for personal use only. You do not have redistribution rights: please do not share, resell, or republish this book or its pages.

© 2026 Steve Hodgkiss. All rights reserved. Personal use only; no redistribution rights.

Edition 1.0 · stevehodgkiss.net

Contents

Contents


Part 1 · The honest wall
The law first4
Part 2 · Two drawers
The five hooks5
Part 3 · Reading one rule
The honest listing6
Part 4 · The wall decides
The --test rehearsal7
Part 5 · The sharp edges
The flush danger8
Part 6 · The wider wall
The successor named9
Part 7 · The long view
Teaching a friend10

Per the Wikipedia Iptables article, iptables requires elevated privileges to operate and must be executed by user root, otherwise it fails to function. Per the Wikipedia Firewall (computing) article, setting up a firewall is a complex and error-prone task, and a network may face security issues due to configuration errors. Per this book's plan, the law is: read with -L and -S, rehearse with iptables-restore --test on a scratch file, and never change a live rule on a host you do not own.

Iptables companion · No. 01
the law

The law first

read, rehearse, never write blind

the law before the first keystroke: whose host, which handsetting up a firewall is acomplex and error-prone taskthis book's law: read with -Land -S, rehearse with --testthe tool must be executed byuser root, per the article:every keystroke is a root one;a write done blind on a hostyou do not own is the wound;every capture in this bookis a read, nothing elseread, rehearse, or write: say which, every single time

Before the first rule, the law. The tool requires elevated privileges to operate and must be executed by user root: every iptables keystroke is a root keystroke.

The red edge, per the Firewall article: setting up a firewall is a complex and error-prone task, and a network may face security issues due to configuration errors.

So this book's law, per this book's plan: read with iptables -L and iptables -S, rehearse with --test, never change a live rule on a host you do not own.

ONE HONEST RULE

Before your next iptables keystroke, say aloud: is this a read, a rehearsal, or a write?

Per the Wikipedia Iptables article, there are five predefined chains mapping to the five available Netfilter hooks, though a table may not have all chains: PREROUTING before a routing decision, INPUT for a packet going to be locally delivered, FORWARD for packets routed and not for local delivery, OUTPUT for packets sent from the machine itself, and POSTROUTING just before handing packets off to the hardware. This machine's capture: iptables -S printed -P INPUT DROP, -P FORWARD DROP and -P OUTPUT ACCEPT.

Iptables companion · No. 02
five doors

The five hooks

predefined chains map to hooks

five predefined chains, one per netfilter hookPREROUTINGbefore routingINPUTlocal deliveryFORWARDrouted throughOUTPUTown sendsPOSTROUTINGthe exitthe filter table carries the threeindigo doors, per the man pagethis host, captured with -S:-P INPUT DROP, FORWARD DROP,OUTPUT ACCEPTfive doors, each with a job; three carry the wall's last words

Five doors, one per hook. Per the article, there are five predefined chains (mapping to the five available Netfilter hooks).

The names: PREROUTING before routing, INPUT for local delivery, FORWARD for routed-through traffic, OUTPUT for own sends, POSTROUTING at the exit.

Our capture: iptables -S answers -P INPUT DROP, FORWARD DROP, OUTPUT ACCEPT: three last words.

ONE HONEST RULE

Point at a packet leaving your machine and name its doors: OUTPUT first, then POSTROUTING.

Per the Wikipedia Iptables article, the command iptables -L -v -n, which shows some chains and their rules, is equivalent to iptables -t filter -L -v -n, and to show chains of table nat, use the command iptables -t nat -L -v -n. Per the local man page synopsis, iptables -t table -S [chain [rulenum]] is one of the command's forms. This machine's captures: iptables -S printed -P INPUT DROP and -A INPUT -j ts-input, and iptables -L -n -v printed Chain INPUT (policy DROP 2426K packets, 127M bytes) with live counters.

Iptables companion · No. 03
the mirror

The honest listing

-L shows the wall, -S speaks it

the honest listing: -L shows, -S speaks$ iptables -S-P INPUT DROP-P FORWARD DROP-A INPUT -j ts-input-N ufw-before-input...81 -A lines in allthe -L mirror, captured:Chain INPUT (policy DROP2426K packets, 127M bytes)live counters, chain by chain;with -v, -L -n equals -t filter -L -n,per the article; nat opens with -t nat -Ltwo mirrors of one wall: quote the one you can read aloud

Two ways to see the wall. -L lays the chains out with live packet and byte counters; -S speaks each rule the way it was written.

Per the article, iptables -L -v -n ... is equivalent to iptables -t filter -L -v -n, and nat opens with iptables -t nat -L -v -n.

Our captures: iptables -S answers -P INPUT DROP then -A INPUT -j ts-input; the -L mirror answers Chain INPUT (policy DROP ...). The wall, seen twice.

ONE HONEST RULE

Run both listings on your host and read row one from each aloud; say which one you would quote.

Per the Wikipedia Iptables article, scripts commonly call iptables or (the faster) iptables-restore with a set of predefined rules. Per this book's plan, the rehearsal is iptables-restore --test against a scratch file: the whole ruleset is parsed and checked, and nothing is loaded. This machine's capture: iptables-restore --test on a five-rule scratch ruleset exited with status 0, changing nothing on this host.

Iptables companion · No. 04
the rehearsal

The --test rehearsal

prove it before you load it

the rehearsal: parse and check, load nothingscratch.rules$ iptables-restore --testexit status 0, capturedthe whole file parsed, every linechecked, and not one rule loadedfive rules inside,the small wall ofpage twenty-seventhe live wall never movedper this book's plan: rehearse, then decidea wall you can rehearse is a wall you can trust

Never load a wall you have not rehearsed. Per the article, scripts call iptables or (the faster) iptables-restore with a set of predefined rules.

Per this book's plan, the rehearsal is iptables-restore --test against a scratch file: parse the whole ruleset, check every line, load nothing.

Our capture: the five-line scratch ruleset ran through --test and the shell answered exit 0. The live wall never moved; that is the point.

ONE HONEST RULE

Write your five-line wall on paper, rehearse it with --test on a scratch file, then decide.

Per the local man page synopsis, the -F form sits beside -L among the chain forms of iptables -t table. Per this book's plan, -F empties the selected chain, every rule gone in one breath. Per the Wikipedia Iptables article, a predefined chain's policy is applied to the packet if it reaches the end of the chain, so a flushed chain falls straight to its policy. No flush was run for this book, and none will be.

Iptables companion · No. 05
the red word

The flush danger

empty is not safe

the red word: -F empties a chain in one breath-Fper plan: empties the chain,every rule gone; an empty chainreaches its policy at onceremote INPUT with DROP lastword: your own knock dieshonest: no flush ran for thisbook, and none willsafe order, per this book'splan: save, rehearse, then changefrom a console your own handis resting on, never far awayempty is not safe: know the ledger and the console first

The red word is -F, listed among the chain forms in the synopsis. Per this book's plan it empties the selected chain: every rule gone in one breath.

Why it locks you out: a policy is applied to the packet if it reaches the end of the chain. An empty chain reaches its end instantly, and with this host's DROP last word, your own knock dies on the floor, remotely.

Honest note: no flush ran for this book, and none will. Per this book's plan the safe order is: save the ledger, rehearse the replacement, then change it, from a console your hand is on.

ONE HONEST RULE

Say the two questions before any flush: where is the saved ledger, and which console is your hand on?

Per the Wikipedia Nftables article, nftables is a subsystem of the Linux kernel providing filtering and classification of network packets, datagrams and frames, it has been available since Linux kernel 3.13 released on 19 January 2014, it replaces the legacy iptables component of Netfilter, and less code duplication is among its advantages. Per the Wikipedia Iptables article, iptables superseded ipchains and the successor of iptables is nftables. This machine's capture: iptables --version answered v1.8.10 (nf_tables), the successor's engine already underneath.

Iptables companion · No. 06
the honest line

The successor named

nftables, 19 January 2014

the lineage named honestly: ipchains, iptables, nftablesipchainssupersedediptablesreleased 2001nftableskernel 3.13nftables since 19 January 2014,replaces the legacy iptables partof netfilter, less code duplicationcaptured: iptables v1.8.10(nf_tables): the new enginealready underneath herelearn the old words, read the new ones; say which you run

The honest line, per the article: nftables has been available since Linux kernel 3.13 released on 19 January 2014, and it replaces the legacy iptables component of Netfilter.

The lineage runs: ipchains, superseded by iptables; iptables, succeeded by nftables, with less code duplication among its advantages.

And the capture's quiet footnote: iptables v1.8.10 (nf_tables). The old keyboard already speaks through the new engine here. Learn the old words; read the new ones.

ONE HONEST RULE

Run your version line and read the word in parentheses aloud; that is your firewall's real engine.

Per this book's plan, the last lesson hands the wall to a friend in one honest hour: the friend types the read-only lines, the teacher reads each answer aloud. The lines behind the hour, all captured on this machine: iptables --version, iptables -S, iptables -L INPUT -n --line-numbers, iptables -t nat -L -n, and iptables-restore --test on the five-line scratch file with exit status 0.

Iptables companion · No. 07
pass it on

Teaching a friend

one honest hour, one friend

pass the wall on: five lines, one friend, one hour1iptables --version2iptables -S3iptables -L INPUT -n --line-numbers4iptables -t nat -L -n5iptables-restore --testthey type; you read aloudall five capturedread-only on thismachine; when thelearner can say why--test loaded nothing,the wall is theirsone honest hour: five lines, read aloud, understood

The last piece is passing the wall on: one friend, one honest hour, per this book's plan. They type; you read aloud.

Five lines, this book's captures: the --version line, the -S ledger, the numbered INPUT rows, the nat drawer, and the --test rehearsal with exit 0.

When they can say what DROP means at the end of INPUT and why --test loaded nothing, the hour is done and the wall is theirs.

ONE HONEST RULE

Sit with one friend and teach this book in one sitting; they type the five read-only lines, you read each answer aloud.

Index

Index


Teaching a friend10
The --test rehearsal7
The five hooks5
The flush danger8
The honest listing6
The law first4
The successor named9