What are the basics of iptables for packet filtering?

Answer

iptables is the Linux kernel-level firewall. It processes packets through chains (INPUT, OUTPUT, FORWARD) within tables (filter, nat, mangle). Rules are checked top-to-bottom; the first match wins. Key commands: iptables -L -n -v lists current rules. iptables -A INPUT -p tcp --dport 80 -j ACCEPT allows inbound TCP on port 80. iptables -A INPUT -j DROP drops everything else (add this last). iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT allows return traffic for existing connections. iptables-save > /etc/iptables/rules.v4 persists rules. On modern systems, nftables and ufw (Ubuntu) or firewalld (RHEL/CentOS) provide friendlier interfaces over the same kernel functionality.