1.在/etc/sysconfig/iptables里添加
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
2.重启iptables
[root@localhost ~]# /etc/init.d/iptables restart
3.看下状态
[root@localhost ~]# /etc/init.d/iptables status
-------------------------------------------------------------------------------------
*filter
:INPUT DROP [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:FWLOG - [0:0]
-A INPUT -i eth0 -p tcp --dport 25 -j DROP
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -s 192.168.0.0/24 -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
COMMIT
这个规则默认DROP,只接受80、主动FTP、SSH服务,如有其它服务可自行添加一行-A INPUT -p tcp -m state --state NEW -m tcp --dport 服务端口 -j ACCEPT 即可