iptables is the user-space utility for configuring Linux kernel firewall rules. It provides powerful packet filtering, network address translation, and connection tracking capabilities.
📑 Table of Contents
Key Features
- Packet Filtering: Accept, drop, or reject packets
- NAT: Source and destination NAT support
- Stateful Inspection: Track connection states
- Logging: Log matching packets
- Chain System: Organized rule processing
Installation
iptables is included in most Linux distributions:
sudo apt install iptables iptables-persistent
Usage Examples
Common iptables rules:
# Allow established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allow HTTP/HTTPS
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
# Drop all other incoming
iptables -A INPUT -j DROP
# Save rules
iptables-save > /etc/iptables/rules.v4
Benefits
iptables provides complete control over network traffic. Its kernel-level filtering ensures efficient processing while flexible rules handle complex security requirements.
Was this article helpful?