当前位置:   article > 正文

CentOS7中使用iptables_centos7 iptables

centos7 iptables

1、关闭firewall:

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

2、安装iptables防火墙

  1. #安装
  2. yum install iptables-services

编辑防火墙配置文件

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

3、关闭SELINUX

vi /etc/selinux/config
  1. #SELINUX=enforcing #注释掉
  2. #SELINUXTYPE=targeted #注释掉
  3. SELINUX=disabled #增加
:wq! #保存退出 
setenforce 0 #使配置立即生效

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/669736
推荐阅读
相关标签
  

闽ICP备14008679号