Mastering iptables: Essential Firewall Tables, Chains, and Commands
Learn the fundamentals of iptables firewall on Linux, including configuration file location, service control commands, the hierarchy of tables, chains, and rules, common targets, and essential iptables commands for listing and flushing rules.
iptables Basics
iptables is the Linux firewall tool that organizes rules into tables, chains, and individual rules.
Location of Configuration
Edit the configuration file with vim /usr/sysconfig/iptables.
Service Control
Use the following commands to manage the iptables service:
service iptables stop service iptables start service iptables restart service iptables saveStructure
iptables → tables → chains → rules.
Tables and Their Built‑in Chains
Filter Table
The default table with three built‑in chains:
INPUT – handles incoming traffic.
OUTPUT – handles outgoing traffic.
FORWARD – forwards traffic to other interfaces.
NAT Table
Provides three built‑in chains for network address translation:
PREROUTING – processes packets before routing, used for DNAT.
POSTROUTING – processes packets after routing, used for SNAT.
OUTPUT – processes locally generated packets.
Mangle Table
Used to alter packet headers; contains five built‑in chains:
PREROUTING
OUTPUT
FORWARD
INPUT
POSTROUTING
Raw Table
Handles packets before connection tracking; has two built‑in chains:
PREROUTING
OUTPUT
Rules
A rule consists of a condition and a target. If the condition matches, the target action is applied; otherwise the next rule is evaluated.
Common Targets
ACCEPT – allow the packet.
DROP – discard the packet.
QUEUE – hand the packet to userspace.
RETURN – stop processing the current chain and return to the calling chain.
Useful Commands
iptables -t filter -L– list rules in the filter table. iptables -t nat -L – list rules in the NAT table. iptables -t mangle -L – list rules in the mangle table. iptables -t raw -L – list rules in the raw table. iptables --flush – delete all rules.
Example Output
Sample listing of the INPUT chain shows rule numbers, targets, protocols, source and destination addresses, and optional match criteria.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
