LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 765|回复: 1

[求助]大家推荐一个slackware下用的防火墙吧..

[复制链接]
发表于 2004-9-19 18:02:27 | 显示全部楼层 |阅读模式

谢谢
大家觉得哪一个比较好/?
发表于 2004-9-20 03:35:23 | 显示全部楼层

看看这个!

IP伪装固太防火墙:(见代)

  1. #!/bin/bash
  2. #Our complete stateful firewall script.  This firewall can be customized for
  3. #a laptop, workstation, router or even a server. :)
  4. #change this to the name of the interface that provides your "uplink"
  5. #(connection to the Internet)
  6. UPLINK="eth1"
  7. #if you're a router (and thus should forward IP packets between interfaces),
  8. #you want ROUTER="yes"; otherwise, ROUTER="no"
  9. ROUTER="yes"
  10. #change this next line to the static IP of your uplink interface for static SNAT, or
  11. #"dynamic" if you have a dynamic IP.  If you don't need any NAT, set NAT to "" to
  12. #disable it.
  13. NAT="1.2.3.4"
  14. #change this next line so it lists all your network interfaces, including lo
  15. INTERFACES="all"
  16. #change this line so that it lists the assigned numbers or symbolic names (from
  17. #/etc/services) of all the services that you'd like to provide to the general
  18. #public.  If you don't want any services enabled, set it to ""
  19. SERVICES="http ftp smtp ssh rsync"
  20. if [ "$1" = "start" ]
  21. then
  22.         echo "Starting firewall..."
  23.         iptables -P INPUT DROP
  24.         iptables -A INPUT -i ! ${UPLINK} -j ACCEPT
  25.         iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  26.         #enable public access to certain services
  27.         for x in ${SERVICES}
  28.         do
  29.                 iptables -A INPUT -p tcp --dport ${x} -m state --state NEW -j ACCEPT
  30.         done

  31.         iptables -A INPUT -p tcp -i ${UPLINK} -j REJECT --reject-with tcp-reset
  32.         iptables -A INPUT -p udp -i ${UPLINK} -j REJECT --reject-with icmp-port-unreachable

  33.         #explicitly disable ECN
  34.         if [ -e /proc/sys/net/ipv4/tcp_ecn ]
  35.         then
  36.                 echo 0 > /proc/sys/net/ipv4/tcp_ecn
  37.         fi
  38.         #disable spoofing on all interfaces
  39.         for x in ${INTERFACES}
  40.         do      
  41.                 echo 1 > /proc/sys/net/ipv4/conf/${x}/rp_filter
  42.         done
  43.         if [ "$ROUTER" = "yes" ]
  44.         then
  45.                 #we're a router of some kind, enable IP forwarding
  46.                 echo 1 > /proc/sys/net/ipv4/ip_forward
  47.                 if [ "$NAT" = "dynamic" ]
  48.                 then
  49.                         #dynamic IP address, use masquerading   
  50.                         echo "Enabling masquerading (dynamic ip)..."
  51.                         iptables -t nat -A POSTROUTING -o ${UPLINK} -j MASQUERADE
  52.                 elif [ "$NAT" != "" ]
  53.                 then
  54.                         #static IP, use SNAT
  55.                         echo "Enabling SNAT (static ip)..."
  56.                         iptables -t nat -A POSTROUTING -o ${UPLINK} -j SNAT --to ${UPIP}192.168.0.1
  57.                 fi
  58.         fi

  59. elif [ "$1" = "stop" ]
  60. then
  61.         echo "Stopping firewall..."
  62.         iptables -F INPUT
  63.         iptables -P INPUT ACCEPT
  64.         #turn off NAT/masquerading, if any
  65.         iptables -t nat -F POSTROUTING
  66. fi
复制代码

时间有限没来的急做代码解释,本人一直在使用它。
(可实现IP转发和伪装)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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