1 vi /etc/sysconfig/iptables
2 # sample configuration for iptables service
3 # you can edit this manually or use system-config-firewall
4 # please do not ask us to add additional ports/services to this default configuration
5 *filter
6 :INPUT ACCEPT [0:0]
7 :FORWARD ACCEPT [0:0]
8 :OUTPUT ACCEPT [0:0]
9 -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
10 -A INPUT -p icmp -j ACCEPT
11 -A INPUT -i lo -j ACCEPT
12
13 -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
14 -A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT
15 -A INPUT -p tcp -m state --state NEW -m tcp --dport 20 -j ACCEPT
16 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
17 -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
18 -A INPUT -j REJECT --reject-with icmp-host-prohibited
19 -A FORWARD -j REJECT --reject-with icmp-host-prohibited
20 COMMIT
21 :wq! #保存退出
22 systemctl restart iptables.service #最后重启防火墙使配置生效
23
24 systemctl enable iptables.service #设置防火墙开机启动