Example of Iptable rules to keep your Linux server safe

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 23 -j ACCEPT
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 81 -j ACCEPT
iptables -A INPUT -p tcp --dport 110 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 587 -j ACCEPT
iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp --dport 8009 -j ACCEPT
iptables -A INPUT -p tcp --dport 8089 -j ACCEPT
iptables -A INPUT -p tcp --dport 8443 -j ACCEPT
iptables -A INPUT -p tcp --dport 8081 -j ACCEPT
iptables -A INPUT -p tcp --dport 81 -j ACCEPT
iptables -A INPUT -p tcp --dport 11211 -j ACCEPT
iptables -A INPUT -p udp --dport 11211 -j ACCEPT
iptables -A INPUT -p tcp --dport 50000 -j ACCEPT
iptables -A INPUT -p tcp --dport 50001 -j ACCEPT
iptables -A INPUT -p tcp --dport 60000 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A INPUT -p tcp --syn -m limit --limit 1/s --limit-burst 3 -j RETURN

You can use -I and with a number to add a rule to the top of the list (highest priority). For example:


iptables -I INPUT 1 -p tcp --sport 80 -j ACCEPT
iptables -I INPUT 1 -p tcp --sport 8080 -j ACCEPT
iptables -I OUTPUT 1 -p tcp --dport 8080 -j ACCEPT
iptables -I OUTPUT 1 -p tcp --dport 80 -j ACCEPT
iptables -I OUTPUT 1 -p tcp --sport 8080 -j ACCEPT
iptables -I OUTPUT 1 -p tcp --sport 80 -j ACCEPT

Refuse all other requests depends on your network settings

iptables -A INPUT -i eth0 -j REJECT
iptables -A INPUT -i venet0 -j REJECT

Save and restart Iptables to active the firewall.

/etc/init.d/iptables save
/etc/init.d/iptables restart

Simple! Isnt it?

Leave a Reply

Your email address will not be published. Required fields are marked *