centos7 停止firewall 启用iptables防火墙

梦里梦外; 2022-01-26 15:19 374阅读 0赞

1、关闭firewall:

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

2、安装iptables防火墙

  1. yum install iptables-services      #安装
  2. vi /etc/sysconfig/iptables        #编辑防火墙配置文件
  3. # sample configuration for iptables service
  4. # you can edit this manually or use system-config-firewall
  5. # please do not ask us to add additional ports/services to this default configuration
  6. *filter
  7. :INPUT ACCEPT [0:0]
  8. :FORWARD ACCEPT [0:0]
  9. :OUTPUT ACCEPT [0:0]
  10. -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
  11. -A INPUT -p icmp -j ACCEPT
  12. -A INPUT -i lo -j ACCEPT
  13. #-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
  14. -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
  15. -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
  16. -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
  17. -A INPUT -m state --state NEW -m tcp -p tcp --dport 5672 -j ACCEPT
  18. -A INPUT -m state --state NEW -m tcp -p tcp --dport 15672 -j ACCEPT
  19. -A INPUT -j REJECT --reject-with icmp-host-prohibited
  20. -A FORWARD -j REJECT --reject-with icmp-host-prohibited
  21. COMMIT

:wq! #保存退出

  1. systemctl restart iptables.service #最后重启防火墙使配置生效
  2. systemctl enable iptables.service #设置防火墙开机启动

发表评论

表情:
评论列表 (有 0 条评论,374人围观)

还没有评论,来说两句吧...

相关阅读