这是Linux中iptables的一个很好的起点吗?

前端之家收集整理的这篇文章主要介绍了这是Linux中iptables的一个很好的起点吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是iptables的新手,我一直在尝试组建一个防火墙,其目的是保护Web服务器.以下规则是我到目前为止所组建的规则,我想听听这些规则是否有意义 – 而且我已经遗漏了任何必要的东西?

除了端口80,我还需要为外部连接打开端口3306(mysql)和22(ssh).

任何反馈都非常感谢!

  1. #!/bin/sh
  2.  
  3. # Clear all existing rules.
  4. iptables -F
  5.  
  6. # ACCEPT connections for loopback network connection,127.0.0.1.
  7. iptables -A INPUT -i lo -j ACCEPT
  8.  
  9. # ALLOW established traffic
  10. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  11.  
  12. # DROP packets that are NEW but does not have the SYN but set.
  13. iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
  14.  
  15. # DROP fragmented packets,as there is no way to tell the source and destination ports of such a packet.
  16. iptables -A INPUT -f -j DROP
  17.  
  18. # DROP packets with all tcp flags set (XMAS packets).
  19. iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
  20.  
  21. # DROP packets with no tcp flags set (NULL packets).
  22. iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
  23.  
  24. # ALLOW ssh traffic (and prevent against DoS attacks)
  25. iptables -A INPUT -p tcp --dport ssh -m limit --limit 1/s -j ACCEPT
  26.  
  27. # ALLOW http traffic (and prevent against DoS attacks)
  28. iptables -A INPUT -p tcp --dport http -m limit --limit 5/s -j ACCEPT
  29.  
  30. # ALLOW MysqL traffic (and prevent against DoS attacks)
  31. iptables -A INPUT -p tcp --dport MysqL -m limit --limit 25/s -j ACCEPT
  32.  
  33. # DROP any other traffic.
  34. iptables -A INPUT -j DROP@H_502_7@

解决方法

试试shorewall,提供开箱即用的合理防火墙.从网络启用对所需服务的访问.有一个,两个和三个接口的示例规则集.文档很好,并且积极维护.

我希望您能够限制哪些地址可以轻松访问MysqL.除非您最近探测过另一个端口,否则您还可以在端口关闭的情况下使用端口敲门来保护SSH.

猜你在找的Linux相关文章