-
-
Notifications
You must be signed in to change notification settings - Fork 1
Linux iptables Guide
Mattscreative edited this page Dec 5, 2025
·
2 revisions
Complete beginner-friendly guide to iptables on Linux, covering Arch Linux, CachyOS, and other distributions including rules, chains, and firewall configuration.
- Understanding iptables
- iptables Installation
- Basic Rules
- Advanced Configuration
- Saving Rules
- Troubleshooting
iptables is packet filtering firewall for Linux.
Components:
- Tables: filter, nat, mangle, raw
- Chains: INPUT, OUTPUT, FORWARD
- Rules: Match and target actions
Common tables:
- filter: Packet filtering (default)
- nat: Network address translation
- mangle: Packet modification
Arch/CachyOS:
# Install iptables
sudo pacman -S iptables
# Install nftables (modern replacement)
sudo pacman -S nftablesDebian/Ubuntu:
sudo apt install iptablesFedora:
sudo dnf install iptables-servicesAllow SSH access:
# Allow SSH (port 22)
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# Allow established connections
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPTAllow localhost:
# Allow loopback
sudo iptables -A INPUT -i lo -j ACCEPTSet default policy:
# Deny all incoming
sudo iptables -P INPUT DROP
# Allow all outgoing
sudo iptables -P OUTPUT ACCEPT
# Deny forwarding
sudo iptables -P FORWARD DROPWeb server rules:
# Allow HTTP
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
# Allow HTTPS
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPTLimit connections:
# Limit SSH connections
sudo iptables -A INPUT -p tcp --dport 22 -m connlimit --connlimit-above 3 -j REJECTArch/CachyOS:
# Save rules
sudo iptables-save > /etc/iptables/iptables.rules
# Restore rules
sudo iptables-restore < /etc/iptables/iptables.rules
# Auto-restore on boot
sudo systemctl enable iptablesDebian/Ubuntu:
sudo netfilter-persistent saveFedora:
sudo service iptables saveList rules:
# List all rules
sudo iptables -L -v -n
# List with line numbers
sudo iptables -L -v -n --line-numbers
# List specific chain
sudo iptables -L INPUT -v -nRemove rules:
# Delete by line number
sudo iptables -D INPUT 1
# Delete specific rule
sudo iptables -D INPUT -p tcp --dport 22 -j ACCEPTThis guide covered iptables configuration for Arch Linux, CachyOS, and other distributions, including basic and advanced rules.
- Firewall Configuration - Firewall setup
- Security Configuration - Security
- ArchWiki iptables: https://wiki.archlinux.org/title/iptables
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.