CentOS7中使用iptables

 1、关闭firewall

1 systemctl stop firewalld.service #停止firewall
2 systemctl disable firewalld.service #禁止firewall开机启动
View Code

2、安装iptables防火墙

1 #安装
2 yum install iptables-services
View Code
编辑防火墙配置文件
 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 #设置防火墙开机启动
View Code

 3、关闭SELINUX

1 vi /etc/selinux/config
2 #SELINUX=enforcing #注释掉
3 #SELINUXTYPE=targeted #注释掉
4 SELINUX=disabled #增加
5 :wq! #保存退出 
6 setenforce 0 #使配置立即生效
View Code
posted @ 2017-05-26 14:33  2206  阅读(236)  评论(0编辑  收藏  举报