I remember when I was in college, the teacher said
Because iptables rules are post-written, the preceding rules are overwritten.
In Linux, the safest firewall rule is to discard all port packets and then enable the required ports one by one.
Now I work, but I still do it in strict accordance with the methods taught by the teacher, but I often encounter many problems and have a long struggle;
The following is an iptables rule that I configured based on the actual needs of my server by constantly querying materials. Thank you very much for your help!
# Generatea by iptabes-save v1.4.7 on Sat Nov 23 10:18:45 2013*filter:INPUT DROP [198:17785]:FORWARD DROP [0:0]:OUTPUT DROP [6:456]-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 3360 -j ACCEPT-A OUTPUT -p tcp -m tcp --sport 22 -j ACCEPT-A OUTPUT -m state --state NEW -m tcp -p tcp --sport 3360 -j ACCEPT-A OUTPUT -p tcp --dport 53 -j ACCEPT-A OUTPUT -p udp --dport 53 -j ACCEPT-A INPUT -m state --state ESTABLISHED -j ACCEPT-A OUTPUT -m state --state ESTABLISHED -j ACCEPT-A OUTPUT -p tcp --dport 80 -j ACCEPT-A INPUT -p tcp --dport 80 -j ACCEPT-A OUTPUT -p tcp --dport 443 -j ACCEPT-A INPUT -p tcp --sport 443 -j ACCEPT-A INPUT -p tcp --dport 21 -j ACCEPT-A INPUT -p tcp --dport 20 -j ACCEPT-A OUTPUT -p tcp --sport 21 -j ACCEPT-A OUTPUT -p tcp --sport 20 -j ACCEPT-A INPUT -p tcp --dport 2092 -j ACCEPT-A OUTPUT -p tcp --sport 2092 -j ACCEPT-A OUTPUT -p tcp --sport 2100 -j ACCEPT-A INPUT -p tcp --dport 2100 -j ACCEPT-A OUTPUT -p tcp --sport 2029 -j ACCEPT-A INPUT -p tcp --dport 2029 -j ACCEPT-A OUTPUT -p tcp --sport 2104 -j ACCEPT-A INPUT -p tcp --dport 2104 -j ACCEPT-A OUTPUT -p tcp --sport 2101 -j ACCEPT-A INPUT -p tcp --dport 2101 -j ACCEPT-A INPUT -p tcp --dport 3306 -j ACCEPT-A INPUT -p udp --dport 3306 -j ACCEPT-A OUTPUT -p tcp --sport 3306 -j ACCEPT-A OUTPUT -p udp --sport 3306 -j ACCEPT-A OUTPUT -p tcp --dport 11211 -j ACCEPT-A INPUT -m state --state NEW,RELATED,ESTABLISHED -j ACCEPTCOMMIT
The strictest iptables rules for centos