免费注册 查看新帖 |

Chinaunix

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

[proxy] 原创:linux+Squid+iptables +透明代理+BT过滤!!! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-03-25 16:35 |只看该作者 |倒序浏览
本人是学校网管,学校带宽经三次升级(2M-->;10M--->;20M---50M)还是不够用查其原因是下面的客户机用BT下载的太多,NAT转发列表达到50000多条。校领导说升了三级网速还是慢,无耐只能把在路由上做策略,除常用端口外其它全部DROP,没几分钟领导又打电话说用FTP下不了软件,打不了游戏!晕!

   由于BT端口不固定,根本没法封,后想到想要BT必须先下载种子,于是就在种子上做了点文章,选用linux+squid+iptables+透明代理过滤种子


   机器配置:Xeon2.4*2/2G DDR/16G SCSI /eth1 1000M   eth2 100M

配置文件:

1、iptables :

这方面的文章很多,不具体说

iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 8001-8010

iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 8011-8020

iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 8080 -j REDIRECT --to-port 8001-8010

iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 8080 -j REDIRECT --to-port 8011-8020

将对TCP 80 8080的访问转发到8001-8020 ,并通过多端口实现负载均衡


iptables -t nat -POSTROUTING -o eth2 -j SNAT --to *.*.*.23-*.*.*.40
实现其它通讯的NAT转发



2、squid


mkdir /dev/shm/tmp
mount --bind /dev/shm/tmp /cache -o size=800M(这个大小根据物理内存的大小定,经多次试验<物理内存50%)

挂接linux的tmpfs文件系统作为Squid的Cache目录提高Cache性能

Squid.conf

visible_hostname loulancn.com.cn
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_uses_host_header on
httpd_accel_single_host off
httpd_accel_with_proxy on
refresh_pattern -i \.html$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.shtml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.htm$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.gif$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.swf$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.jpg$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.png$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.bmp$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \.js$ 1440 90% 129600 reload-into-ims
refresh_pattern .      0       20%     10
cache_dir ufs /cache 800 16 256
cache_mgr loulancn@163.com
cache_mem 100 MB
cache_effective_user squid
cache_effective_group squid
acl badurlbt urlpath_regex -i \.torrent$   ---过滤.torrent文件
acl btchina url_regex btchina   -----------过滤部分特殊网站,随时增加
acl btbbt url_regex btbbt
acl btfans url_regex btfans
acl all src 0.0.0.0/0.0.0.0
http_access deny badurlbt
http_access deny btchina
http_access deny btbbt
http_access deny btfans
http_access allow all
deny_info about:blank badurlbt          ------------被过滤时打开的地址,为了“透明”
deny_info about:blank btchina
deny_info about:blank btbbt
deny_info about:blank btfans





本人暂时能做的就只有这么多了,欢迎大家一起交流共享!也请高人指教!

论坛徽章:
0
2 [报告]
发表于 2005-03-25 16:57 |只看该作者

原创:linux+Squid+iptables +透明代理+BT过滤!!!

“BT过滤”部分在哪里?

论坛徽章:
0
3 [报告]
发表于 2005-03-25 17:14 |只看该作者

原创:linux+Squid+iptables +透明代理+BT过滤!!!

--------------------------------------------------------------------------
acl badurlbt urlpath_regex -i \.torrent$   ---过滤.torrent文件
acl btchina url_regex btchina   -----------过滤部分特殊网站,随时增加
acl btbbt url_regex btbbt         
acl btfans url_regex btfans

--------------------------------------------------------------------------

这部分是实现对BT种子的过滤,可以起到一定效果,不过不是很理想,因为好多BT网站用的是非常规端口 如非80、8080


这里只是一个抛砖引玉的作用!

大家有什么好的方法也可以拿出来分享呀!

呵呵!

论坛徽章:
0
4 [报告]
发表于 2005-03-25 17:20 |只看该作者

原创:linux+Squid+iptables +透明代理+BT过滤!!!

感觉效果可能不会很理想,不过这个创意挺好^_^

封杀BT、电驴、下吧等P2P工具,最好用ipp2p或者l7-filter模块

论坛徽章:
0
5 [报告]
发表于 2005-03-25 21:55 |只看该作者

原创:linux+Squid+iptables +透明代理+BT过滤!!!

那大师有什么好的办法?或者配置ipp2p或者l7-filter模块的文档?

论坛徽章:
0
6 [报告]
发表于 2005-03-26 01:45 |只看该作者

原创:linux+Squid+iptables +透明代理+BT过滤!!!

ipp2p的用法很简单,比如你要阻止BT和电驴
iptables -I FORWARD -m ipp2p --bit --edk -j DROP
前提是,你的netfilter必须支持这个模块,iptables里面必须有这个模块
我写过一个如何给iptables添加模块的文档,你可以借鉴一下
http://bbs.chinaunix.net/forum/viewtopic.php?t=505370

论坛徽章:
0
7 [报告]
发表于 2005-03-26 09:10 |只看该作者

原创:linux+Squid+iptables +透明代理+BT过滤!!!

借地问楼主个问题

设置透明代理,iptables要不要写NAT的语句?

如果只写下面这句80端口转发,那是不是所有和网络程序都可正常使用,就像NAT一样
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128

论坛徽章:
0
8 [报告]
发表于 2005-03-26 11:21 |只看该作者

原创:linux+Squid+iptables +透明代理+BT过滤!!!

[quote="twodog29"]如果只写下面这句80端口转发,那是不是所有和网络程序都可正常使用,就像NAT一样
iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
[quote]
先了解squid,知道squid能做什么,不能做什么,对你TroubleShooting会有很大帮助^_^

论坛徽章:
0
9 [报告]
发表于 2005-03-26 16:28 |只看该作者

原创:linux+Squid+iptables +透明代理+BT过滤!!!

问题就在于不太了解啊。个人理解是squid是用来作web代理的。

我的iptables只写了80端口转发那句话,但QQ和BT可以正常使用,按理说还要写NAT的。怀疑AS3是不是已经打开了网关服务?

这段时间已经被困扰了很久………………

论坛徽章:
0
10 [报告]
发表于 2005-03-28 18:45 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP