全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 1291|回复: 9
打印 上一主题 下一主题

软防火墙?脚本一段,cpanel Plesk DirectAdmin 也适用

[复制链接]
跳转到指定楼层
1#
发表于 2011-5-3 17:36:35 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
刚到处晃悠发现的,求加分
1) Download the script to your server. We provide pre-configured variants of the script to just work "out of the box" on your VPS. Choose the appropriate script and run the following command as root.
# no panel ports
wget -O /etc/init.d/firewall http://vpsinfo.nixhost.net/firewall.vps

# cpanel specific ports opened
wget -O /etc/init.d/firewall http://vpsinfo.nixhost.net/firewall.cpanel.vps

# DirectAdmin specific ports opened
wget -O /etc/init.d/firewall http://vpsinfo.nixhost.net/firewall.directadmin.vps

# Plesk specific ports opened
wget -O /etc/init.d/firewall http://vpsinfo.nixhost.net/firewall.psa.vps

This is where the security concious will not take our word for anything and thoroughly read the script first. Go ahead, we'll wait.

2) Make it executable

chmod +x /etc/init.d/firewall

3) Configure it to start at boot

/sbin/chkconfig firewall on

4) Start it.

/sbin/service firewall start
or
/etc/init.d/firewall start

5) See the rules

/sbin/service firewall status
  1. #!/bin/bash

  2. #
  3. # firewall      This shell script takes care of setting up a firewall for a virtuosso based VPS
  4. #               (no stateful rules/connection tracking or logging.
  5. #               Borrows heavily from a script by Dmitry Konstantinov of sw-soft
  6. #
  7. #
  8. # chkconfig: 2345 18 92
  9. # description: setup firewall configuration

  10. IPTABLES="/sbin/iptables"
  11. SERVER_IPS=`/sbin/ifconfig | grep inet | cut -d : -f 2 | cut -d \  -f 1 | grep -v 127.0.0.1`

  12. FWIN="${IPTABLES} -A INPUT"
  13. FWOUT="${IPTABLES} -A OUTPUT"
  14. OK="-j ACCEPT"
  15. NO="-j DROP"


  16. # Flush tables and change default policy to DROP
  17. function initialize() {
  18.         local TABLE="${1}"
  19.         ${IPTABLES} -F ${TABLE}
  20.         ${IPTABLES} -P ${TABLE} DROP
  21. }

  22. # Flush tables and change default policy to ACCEPT
  23. function stop() {
  24.         local TABLE="${1}"
  25.         ${IPTABLES} -F ${TABLE}
  26.         ${IPTABLES} -P ${TABLE} ACCEPT
  27. }

  28. # Verify call switch
  29. case "$1" in
  30. start|restart)

  31.         initialize INPUT
  32.         initialize OUTPUT
  33.         initialize FORWARD
  34.         
  35.          # INPUT
  36.          # 1) loopback
  37.          ${FWIN} -i lo ${OK}
  38.          ${FWIN} -d 127.0.0.0/8 ${NO}
  39.          
  40.          # 2) We allow incoming SSH connections and answers to
  41.          # our own SSH connections:
  42.          for OURIP in ${SERVER_IPS}; do
  43.             ${FWIN} -p tcp -d ${OURIP} --dport 22 ${OK}
  44.             ${FWIN} -p tcp --sport 22 -d ${OURIP} "!" --syn ${OK}
  45.          done
  46.          
  47.          # 3) We allow incoming DNS queries as well as answers to our
  48.          # DNS queries.
  49.          for OURIP in ${SERVER_IPS}; do
  50.             ${FWIN} -p tcp -d ${OURIP} --dport 53 ${OK}
  51.             ${FWIN} -p udp -d ${OURIP} --dport 53 ${OK}
  52.             ${FWIN} -p tcp --sport 53 -d ${OURIP} --dport 1024: "!" --syn ${OK}
  53.             ${FWIN} -p udp --sport 53 -d ${OURIP} --dport 1024: ${OK}
  54.          done
  55.          
  56.          # 4) We allow access to our SMTP server, as well as answers
  57.          # to our SMTP connections and, temporarily, identd stuff:
  58.          for OURIP in ${SERVER_IPS}; do
  59.             ${FWIN} -p tcp -d ${OURIP} --dport 25 ${OK}
  60.             ${FWIN} -p tcp --sport 25 -d ${OURIP} --dport 1024: "!" --syn ${OK}
  61.             ${FWIN} -p tcp --sport 1024: -d ${OURIP} --dport 113 ${OK}
  62.             #${FWIN} -p udp --sport 1024: -d ${OURIP} --dport 113 ${OK}
  63.             ${FWIN} -p tcp --sport 113 -d ${OURIP} --dport 1024: "!" --syn ${OK}
  64.             #${FWIN} -p udp --sport 113 -d ${OURIP} --dport 1024: ${OK}
  65.          done
  66.          
  67.          # 5) We also allow access to our POP/sPOP server.
  68.          for OURIP in ${SERVER_IPS}; do
  69.            ${FWIN} -p tcp -d ${OURIP} --dport 110 ${OK}
  70.            ${FWIN} -p tcp -d ${OURIP} --dport 995 ${OK}
  71.          done
  72.          
  73.          # 6) and to IMAP/IMAPs
  74.          for OURIP in ${SERVER_IPS}; do
  75.             ${FWIN} -p tcp -d ${OURIP} --dport 143 ${OK}
  76.             ${FWIN} -p tcp -d ${OURIP} --dport 993 ${OK}
  77.          done
  78.          
  79.          # 7) we would like to be able to use lynx ;)
  80.          for OURIP in ${SERVER_IPS}; do
  81.          ${FWIN} -p tcp --sport 80 -d ${OURIP} --dport 1024: "!" --syn ${OK}
  82.          done
  83.          
  84.          # 8) We allow incoming echo replies/requests from everywhere:
  85.          for OURIP in ${SERVER_IPS}; do
  86.             ${FWIN} -p icmp -d ${OURIP} --icmp-type 0 ${OK}
  87.             ${FWIN} -p icmp -d ${OURIP} --icmp-type 3 ${OK}
  88.             ${FWIN} -p icmp -d ${OURIP} --icmp-type 8 ${OK}
  89.             ${FWIN} -p icmp -d ${OURIP} --icmp-type 11 ${OK}
  90.          done
  91.          
  92.          # 9) We also would like to allow access to our web server:
  93.          for OURIP in ${SERVER_IPS}; do
  94.             ${FWIN} -p tcp -d ${OURIP} --dport 80 ${OK}
  95.             ${FWIN} -p tcp -d ${OURIP} --dport 443 ${OK}
  96.          done

  97.          # 10) people are still crazy enough to use ftp
  98.          for OURIP in ${SERVER_IPS}; do
  99.            for PORT in 20 21; do
  100.              ${FWIN} -p tcp -d ${OURIP} --dport ${PORT} ${OK}
  101.              ${FWIN} -p tcp --sport  ${PORT} -d ${OURIP} --dport 1024: "!" --syn ${OK}
  102.              ${FWIN} -p udp -d ${OURIP} --dport ${PORT} ${OK}
  103.              ${FWIN} -p udp --sport ${PORT} -d ${OURIP} --dport 1024: ${OK}
  104.            done
  105.          done
  106.         
  107.          # allow answers on high ports
  108.          ${FWIN} -p tcp -m tcp --dport 1024:65535 ! --tcp-flags SYN,RST,ACK SYN -j ACCEPT
  109.          ${FWIN} -p udp -m udp --dport 1024:65535 -j ACCEPT

  110.          # passive ftp
  111.          # configure ftp server to allow passive ftp on ports outside of
  112.          # the local range. Check local range with
  113.          # cat /proc/sys/net/ipv4/ip_local_port_range
  114.          #
  115.          # for pure-ftpd, use --passiveportrange 61001:65535 in
  116.          # /etc/sysconfig/pure-ftpd
  117.          #
  118.          # for proftpd use PassivePorts  61001 65535
  119.          # in /etc/proftpd.conf
  120.          #
  121.          #${FWIN} -p tcp -m tcp --dport 61001:65535 ${OK}       
  122.          
  123.          # Everything else is denied by default - policy is DROP.
  124.          
  125.          # OUTPUT
  126.          # 1) Loopback packets.
  127.          ${FWOUT} -o lo ${OK}
  128.          ${FWOUT} -s 127.0.0.0/8 ${NO}
  129.          
  130.          # 2) We allow all outgoing traffic:
  131.          for OURIP in ${SERVER_IPS}; do
  132.             ${FWOUT} -s ${OURIP} ${OK}
  133.          done
  134.         
  135.         ;;

  136. stop)
  137.         # turn off the firewall, flush all rules
  138.         echo "Flushing rulesets.."

  139.         stop INPUT
  140.         stop OUTPUT
  141.         stop FORWARD

  142.         ;;

  143. status)
  144.         # display the current status - both firewall rules and masquerading
  145.         # connections

  146.         # list rules. -n avoids DNS lookups
  147.         $IPTABLES -nL

  148.         ;;

  149. *)
  150.         echo "Usage: firewall {start|stop|restart|status}"
  151.         exit 1
  152. esac

  153. exit 0
复制代码

[ 本帖最后由 winder 于 2011-5-3 17:46 编辑 ]
2#
发表于 2011-5-3 17:42:53 | 只看该作者
cenots的导入防火墙规则的?
3#
发表于 2011-5-3 17:45:40 | 只看该作者
偶现在不敢弄了,上次我弄了一个,把我弄的啪唧啪唧的。
4#
 楼主| 发表于 2011-5-3 17:46:05 | 只看该作者
原帖由 ATOM 于 2011-5-3 17:42 发表
cenots的导入防火墙规则的?

编辑了下.重新看
5#
发表于 2011-5-3 18:03:19 | 只看该作者
头晕
6#
发表于 2011-5-3 18:18:26 | 只看该作者
我回铁是因为我蛋铜
i65u 该用户已被删除
7#
发表于 2011-5-3 18:24:32 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
8#
发表于 2011-5-3 18:45:13 | 只看该作者
具体啥作用?
9#
发表于 2011-5-3 18:56:34 | 只看该作者
最怕脚本错误
10#
 楼主| 发表于 2011-5-3 22:13:27 | 只看该作者
原帖由 DSN 于 2011-5-3 18:45 发表
具体啥作用?

具体已经更新上去了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2025-11-10 03:27 , Processed in 0.085302 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表