This guide is for learning. Run these commands only on your own lab or servers.
iptables filters packets using rules grouped in chains. INPUT handles traffic coming to the machine, OUTPUT traffic leaving it and FORWARD traffic passing through.
1. See what exists
sudo iptables -L -n -v2. Allow established traffic and SSH first
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT3. Drop the rest
sudo iptables -P INPUT DROP4. Save the rules
sudo apt install iptables-persistent
sudo netfilter-persistent saveAdd the SSH rule before you set the DROP policy. Test on a lab virtual machine first.
Want every command on one page? Linux & Enterprise Configuration Guide · $9.99View on Gumroad



