免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 7328 | 回复: 14
打印 上一主题 下一主题

[proxy] 回复-置顶: linux+squid+iptables企业方案征集 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-12-17 01:38 |只看该作者 |倒序浏览
申明,本人脚本禁止转载,请尊重本人劳动成果:
试试:
首先本人认为01 是不可能实现的,而11我又不会SQL和SAMBA认证只会基本认证,除此之外其余均能实现
假设子网192.168.1.0/24,某个域名为www.163.com通过PING 的其IP为202.108.36.196,通过其IP限制收发该域名邮件(可在iptables中实现)
外网网卡为eth0内网网卡为eht1,为eth1绑定192.168.1.201和192.168.0.201
cp eth1 eth1:1
修改eht1:1
没有限制的用户为192.168.0.201以后的IP用MAC标志
由于AS3没有安装GCC而本身的SQUID里又没有NCSA文件,固重新安装GCC和SQUID,
tar zxvf squid-2.5.STABLE7.tar.gz
cd squid-2.5.STABLE7
./configure --prefix=/usr/local/squid
--sysconfdir=/etc/squid                                   #配置文件位置
--enable-arp-acl                                         #客户端的MAC地址进行管理
--enable-linux-netfilter                                  #允许使用Linux的透明功能
--enable-pthreads
--enable-err-language="Simplify_Chinese"  
--enable-default-err-language="Simplify_Chinese"
#上面两个选项告诉Squid编入并使用简体中文错误信息
--enable-storeio=ufs,null                                #可以不用缓冲
--enable-auth="basic"                                 #认证方式
--enable-baisc-auth-helpers="NCSA"                    #认证程序为
--enable-underscore                                   #允许解析的URL中出现下划线
make
make install
开始配置squid.conf
##################################################################################################
# 服务器配置
icp_port 0
cache_store_log none
cache_access_log /dev/null   
cache_log /dev/null           
http_port 3128
cache_mem 128 MB
cache_dir null /tmp

pid_filename none
client_netmask 255.255.255.255
half_closed_clients on

#用户分类                                         
auth_param basic program /usr/bin/ncsa_auth /usr/etc/passwd
auth_param basic children 5
auth_param basic realm Tianfuming proxy-caching server
auth_param basic credentialsttl 2 hours
acl normal proxy_auth REQUIDE              #用户认证
acl advance arp 00:01:02:1f:2c:3e 00:01:02:3c:1a:8b ...   #10 IP/MAC绑定用户名认证上网;
acl lana src 192.168.1.0/24
acl lanb src 192.168.0.1-192.168.0.200/32

#行为分类
acl download urlpath_regex -i \.mp3$ \.exe$ \.avi$ \.rar$ \.rvmb$ \.jpg  #禁止下载
#acl conncount maxconn 5               #最大连接数
acl worktime MTWHF 8:00-18:00         # 04、允许全体人员在固定时间,有部分限制,
#不在此时间之内,撤除限制(在http_access中限制)
acl qq dstdomain .snnu.edu.cn
acl badwords url_regex sex

acl localhost src 127.0.0.1/32
acl all src 0.0.0.0/0.0.0.0

http_access allow advance                 # 03 允许部分人完全没有限制;
http_access allow localhost
#http_access deny conncount normal
http_access deny !
http_access deny badwords worktime         # 不允许访问特定url字符网站
http_access deny qq worktime               # 06 不允许访问特定的站点
http_access allow lana                     # 02 允许部分人可以下载
http_access deny download  worktime        # 05 不允许下载的特定url字符:exe/zip等等;
http_access allowd lanb homepage           #08、允许部分人员只能浏览指定网站;
http_access allow normal
http_access deny all                      #除这些,禁止所有
#结合透明代理   07、透明代理与用户认证共存
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
####################################################################################
iptables脚本
####################################################################################
#! /bin/sh

UPLINK="eth0"
UPIP="a.b.c.d"
LANLINK="eth1"
ROUTER="yes"
#NAT="UPIP/dynamic"
NAT="UPIP"
INTERFACES="lo eth0 eth1"
SERVICES="80 22 25 110 "
deny=""
case "$@" in
start)
        echo -n "Starting firewall..."
        modprobe ip_nat_ftp
        modprobe ip_conntrack_ftp
        iptables -P INPUT DROP
        iptables -A INPUT -i ! ${UPLINK} -j  ACCEPT
        iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
        iptables -A FORWARD DROP
        iptables -A FORWARD -p tcp -m multiport --dport 25 80 110 -j ACCEPT
        iptables -A FORWARD -d !202.108.36.196 -p tcp -m multiport --dprot 25 110 -j DROP  ##09、只允许收发邮件(所有域名邮件
        iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT     #(smtp,pop3))和只能收某域名收发某域名邮件
        #iptables -P OUTPUT DROP
        #enable public access to certain services
        for x in ${SERVICES}
        do
                iptables -A INPUT -p tcp --dport ${x} -m state --state NEW -j ACCEPT
        done

        for y in ${deny}
        do
                iptables -A OUTPUT -p tcp --dport ${y} -j DROP
                iptables -A OUTPUT -p udp --dport ${y} -j DROP
        done

        #enable system-log
        #iptables -A INPUT -j LOG --log-prefix "bad input:"

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

        #explicitly disable ECN
        if [ -e /proc/sys/net/ipv4/tcp_ecn ]
        then
                echo 0 >; /proc/sys/net/ipv4/tcp_ecn
        fi

        #disable spoofing on all interfaces
        for x in ${INTERFACES}
        do
                echo 1 >; /proc/sys/net/ipv4/conf/${x}/rp_filter
        done

        if [ "$ROUTER" = "yes" ]
        then
                #we're a router of some kind, enable IP forwarding
                echo 1 >; /proc/sys/net/ipv4/ip_forward
                if [ "$NAT" = "dynamic" ]
                then
                        #dynamic IP address, use masquerading
                        iptables -t nat -A POSTROUTING -o ${UPLINK} -j MASQUERADE
                elif [ "$NAT" != "" ]
                then
                        #static IP, use SNAT
                        iptables -t nat -A PREROUTING -i ${LANLINK} -d ! ${UPIP} -j DNAT --to-ports 3128
                        iptables -t nat -A POSTROUTING -o ${UPLINK} -j SNAT --to ${UPIP}
                fi
        fi
        echo "OK!"
        exit 0
;;
stop)
        echo -n "Stopping firewall..."
        iptables -F INPUT
        iptables -P INPUT ACCEPT
        iptables -F OUTPUT
        iptables -P OUTPUT ACCEPT
        #turn off NAT/masquerading, if any
        #iptables -t nat -F POSTROUTING
        echo "OK!"
        exit 0
;;
restart)
        $0 stop
        $0 start

;;
show)
        clear
        echo ">;-------------------------------------------------------------------"
        iptables -L
        echo ">;-------------------------------------------------------------------"
        iptables -t nat -L POSTROUTING
        exit 0
;;
*)
        echo "Usage: $0 {start|stop|restart|show}"
        exit 1
esac

论坛徽章:
0
2 [报告]
发表于 2004-12-20 01:42 |只看该作者

回复-置顶: linux+squid+iptables企业方案征集

多谢,并请大家测试。

PS:可能不会搞代理了,但是希望能给大家提供交流的平台。

论坛徽章:
0
3 [报告]
发表于 2004-12-22 19:19 |只看该作者

回复-置顶: linux+squid+iptables企业方案征集

晕倒,这么好的东东竟然没有人顶...........................

楼主我帮你测试,有什么问题请教你.

我的MSN: chris_wan@hotmail.com (24小时在线)

        QQ:278352648 (不是常在线)

论坛徽章:
0
4 [报告]
发表于 2004-12-22 19:22 |只看该作者

回复-置顶: linux+squid+iptables企业方案征集

强列建议加精--置顶!

论坛徽章:
0
5 [报告]
发表于 2004-12-24 19:00 |只看该作者

回复-置顶: linux+squid+iptables企业方案征集

谢谢

论坛徽章:
0
6 [报告]
发表于 2004-12-28 16:59 |只看该作者

回复-置顶: linux+squid+iptables企业方案征集

好象有点错误,请看

[root@sztl-fw2 firewall]# ./firewall.sh
Usage: ./firewall.sh {start|stop|restart|show}
[root@sztl-fw2 firewall]# ./firewall.sh start
Starting firewall...Bad argument `DROP'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `80'
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.8: Unknown arg `--dprot'
Try `iptables -h' or 'iptables --help' for more information.
iptables v1.2.8: Unknown arg `--to-ports'
Try `iptables -h' or 'iptables --help' for more information.
OK!
[root@sztl-fw2 firewall]# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere           
ACCEPT     all  --  anywhere             anywhere           state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere           tcp dpt:http state NEW
ACCEPT     tcp  --  anywhere             anywhere           tcp dpt:ssh state NEW
ACCEPT     tcp  --  anywhere             anywhere           tcp dpt:smtp state NEW
ACCEPT     tcp  --  anywhere             anywhere           tcp dpt:pop3 state NEW
REJECT     tcp  --  anywhere             anywhere           reject-with tcp-reset

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere           state RELATED,ESTABLISHED

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
[root@sztl-fw2 firewall]# iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
SNAT       all  --  anywhere             anywhere           to:192.168.9.1

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

论坛徽章:
0
7 [报告]
发表于 2005-01-03 11:39 |只看该作者

回复-置顶: linux+squid+iptables企业方案征集

嗯,怎么没人回呢

论坛徽章:
0
8 [报告]
发表于 2005-01-04 12:09 |只看该作者

回复-置顶: linux+squid+iptables企业方案征集

你把该脚本放到/sbin下然后chmod +x /sbin/firewall
然后/sbin/firewall start试试

论坛徽章:
0
9 [报告]
发表于 2005-01-14 15:11 |只看该作者

回复-置顶: linux+squid+iptables企业方案征集

  1. tianfuming
  2. 你好,你在这里说到可以
复制代码
  1. 重新安装GCC
复制代码

我想问一下是怎么个装法,我没有Rhat9 的光盘。

论坛徽章:
0
10 [报告]
发表于 2005-01-18 16:44 |只看该作者

回复-置顶: linux+squid+iptables企业方案征集

支持.!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP