I want to allow only SSH access, FTP access and all communications between my Dedicated Server and all Cloudflare Servers using IPTables. I tried the commands beneath but it seems like I kicked out myself and I don't know what I have done wrong:
# Allow FTP and SSH for our staff
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
# Allow all Cloudflare IPv4 and IPv6
for i in `curl https://www.cloudflare.com/ips-v4`; do iptables -A INPUT -p tcp --source $i --dport 80 -j ACCEPT; done
for i in `curl https://www.cloudflare.com/ips-v6`; do ip6tables -A INPUT -p tcp --source $i --dport 443 -j ACCEPT; done
# make sure nothing comes or goes out of this box
iptables -A INPUT -j DROP
iptables -A OUTPUT -j DROP
ip6tables -A INPUT -j DROP
iptables-save > /etc/sysconfig/iptables
ip6tables-save > /etc/sysconfig/ip6tables
apt-get install iptables-persistent
service iptables-persistent start
service iptables-persistent save
After executing this row I got kicked by SSH: iptables -A OUTPUT -j DROP
.
Also FTP has not worked anymore. What is wrong there??