用于生产环境的 iptables rule

  1. #用于生产环境的 iptables rule,开启了常用的端口 22 80 25 110 8080 3306 等,如果 sshd 端口不是 22,需要自行修改脚本。

  2. iptables -F  
  3. iptables -X  
  4. iptables -t nat -F  
  5. iptables -t nat -X  
  6.   
  7. # 开放 sshd  
  8. iptables -A INPUT -p tcp --dport 22 -j ACCEPT  
  9. iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT  
  10. iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT  
  11.   
  12. # DROP 掉所有的包  
  13. iptables -P INPUT ACCEPT   
  14. iptables -P OUTPUT ACCEPT  
  15. iptables -P FORWARD ACCEPT  
  16.   
  17. # 本机放行  
  18. iptables -t filter -I INPUT 1 -i lo -j ACCEPT  
  19. iptables -t filter -I OUTPUT 1 -o lo -j ACCEPT  
  20.   
  21. # DNS  
  22. iptables -A INPUT -p udp --sport 53 -j ACCEPT  
  23. iptables -A OUTPUT -p udp --dport 53 -j ACCEPT  
  24. iptables -A INPUT -p udp --dport 53 -j ACCEPT  
  25. iptables -A OUTPUT -p udp --sport 53 -j ACCEPT  
  26.   
  27. # NFS  
  28. iptables -A INPUT -p tcp --dport=111 -j ACCEPT  
  29. iptables -A OUTPUT -p tcp --sport=111 -j ACCEPT  
  30. iptables -A INPUT -p tcp --dport=2049 -j ACCEPT  
  31. iptables -A OUTPUT -p tcp --sport=2049 -j ACCEPT  
  32.   
  33. #sendmail  
  34. iptables -A INPUT -p tcp --dport 25 -j ACCEPT  
  35. iptables -A OUTPUT -p tcp --sport 25 -j ACCEPT  
  36. iptables -A OUTPUT -p tcp --dport 25 -j ACCEPT  
  37. iptables -A INPUT -p tcp --dport 110 -j ACCEPT  
  38. iptables -A OUTPUT -p tcp --sport 110 -j ACCEPT  
  39. iptables -A OUTPUT -p tcp --dport 110 -j ACCEPT  
  40.   
  41. #sms  
  42. iptables -A INPUT -p tcp --dport 8060 -j ACCEPT  
  43. iptables -A OUTPUT -p tcp --sport 8060 -j ACCEPT  
  44. iptables -A OUTPUT -p tcp --dport 8060 -j ACCEPT  
  45.   
  46. # SAMBA  
  47. iptables -A INPUT -p tcp --dport=139 -j ACCEPT  
  48. iptables -A OUTPUT -p tcp --sport=139 -j ACCEPT  
  49. iptables -A INPUT -p tcp --dport=445 -j ACCEPT  
  50. iptables -A OUTPUT -p tcp --sport=445 -j ACCEPT  
  51. iptables -A INPUT -p udp --dport=137 -j ACCEPT  
  52. iptables -A OUTPUT -p udp --sport=137 -j ACCEPT  
  53. iptables -A INPUT -p udp --dport=138 -j ACCEPT  
  54. iptables -A OUTPUT -p udp --sport=138 -j ACCEPT  
  55.   
  56. # 21, yum  
  57. iptables -A INPUT -p tcp --dport 21 -j ACCEPT  
  58. iptables -A OUTPUT -p tcp --sport 21 -j ACCEPT  
  59. iptables -A OUTPUT -p tcp --dport 21 -j ACCEPT  
  60.   
  61.   
  62. # 80  
  63. iptables -A INPUT -p tcp --dport=80 -j ACCEPT  
  64. iptables -A OUTPUT -p tcp --sport=80 -j ACCEPT  
  65. iptables -A OUTPUT -p tcp --dport=80 -j ACCEPT  
  66.   
  67. # 8080  
  68. iptables -A INPUT -p tcp --dport=8080 -j ACCEPT  
  69. iptables -A OUTPUT -p tcp --sport=8080 -j ACCEPT  
  70. iptables -A OUTPUT -p tcp --dport=8080 -j ACCEPT  
  71.   
  72. # 443  
  73. iptables -A INPUT -p tcp --dport=443 -j ACCEPT  
  74. iptables -A OUTPUT -p tcp --sport=443 -j ACCEPT  
  75. iptables -A OUTPUT -p tcp --dport=443 -j ACCEPT  
  76.   
  77. # 3306,只允许 192.168.0.2 连接  
  78. iptables -A INPUT -p tcp --dport=3306 -j ACCEPT  
  79. iptables -A OUTPUT -p tcp --sport=3306 -j ACCEPT  
  80. iptables -A OUTPUT -p tcp --dport=3306 -j ACCEPT  
  81. iptables -A INPUT -p udp --dport=3306 -j ACCEPT  
  82. iptables -A OUTPUT -p udp --sport=3306 -j ACCEPT  
  83.   
  84.   
  85. #rsync  
  86. iptables -A INPUT -p tcp -s 114.113.229.234 --sport 1024:65535 --dport 873 -j ACCEPT  
  87. iptables -A INPUT -p tcp -s 192.168.0.1/3 --sport 1024:65535 --dport 873 -j ACCEPT  
  88. iptables -A OUTPUT -p tcp -d 114.113.229.234 --dport 1024:65535 --sport 873 -j ACCEPT  
  89. iptables -A OUTPUT -p tcp -d 192.168.0.1/3 --dport 1024:65535 --sport 873 -j ACCEPT  
  90.   
  91. #3690 svn  
  92. iptables -A INPUT -p tcp --dport=3690 -j ACCEPT  
  93. iptables -A OUTPUT -p tcp --sport=3690 -j ACCEPT  
  94. iptables -A OUTPUT -p tcp --dport=3690 -j ACCEPT  
  95.   
  96. # DHCP  
  97. iptables -A INPUT -p udp --sport 67 --dport 68 -j ACCEPT  
  98.   
  99. # ICMP  
  100. iptables -A INPUT -p icmp -j ACCEPT  
  101. iptables -A OUTPUT -p icmp -j ACCEPT  
  102.   
  103. #allow old connection, deny new connection  
  104. iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT  
  105. iptables -A INPUT -m state --state NEW,INVALID -j DROP  
  106.   
  107. iptables -P INPUT DROP  
  108. iptables -P OUTPUT DROP  
  109. iptables -P FORWARD DROP  
  110.   
  111.   
  112. /etc/init.d/iptables save  
  113. chkconfig iptables --level 2345 on  
  114.   
  115. service iptables start  
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值