Common Linux Commands – Part 5
5. iptables Firewall: Four Tables and Five Chains:
The default four rule tables:
raw table: Determines whether to track the state of the packet, includes rule chains OUTPUT, PREROUTING
mangle table: Modifies packet content, used for traffic shaping, sets packet marks, includes rule chains INPUT, OUTPUT, FORWARD, PREROUTING, POSTROUTING
nat table: Responsible for Network Address Translation, modifies source and destination IP addresses or ports in packets, includes rule chains OUTPUT, PREROUTING, POSTROUTING
filter table: Responsible for filtering packets, determines whether to allow the packet (filtering), includes rule chains INPUT, OUTPUT, FORWARD
The default five rule chains:
INPUT: Handles incoming packets
OUTPUT: Handles outgoing packets
FORWARD: Handles forwarded packets
PREROUTING: Processes packets before routing
POSTROUTING: Processes packets after routing
iptables command syntax format:
iptables -t filter -A INPUT -s 10.1.1.1 -p tcp --dport 22 -j DROP
[iptables] [-t table name] [-A INPUT chain head] [-s 10.1.1.1 -p tcp --dport 22 condition match] [-j DROP action to execute]