免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: 100000
打印 上一主题 下一主题

pf如何限制每ip的最大连接数(已解决)。能否限制每ip的最大带宽? [复制链接]

论坛徽章:
0
31 [报告]
发表于 2006-01-17 15:11 |只看该作者
原帖由 100000 于 2006-1-17 15:01 发表


要求严格。
我目前每ip限制了50连接数


很多用户用不到50个, 一般20-30个左右, 当然bt, emule 等下载量大的用户不是。我现在只是查找并发连接最多的IP, 封最大的一个基本上网速就上去了! 再不行就封第二个最多的!

论坛徽章:
2
丑牛
日期:2013-09-29 09:47:222015七夕节徽章
日期:2015-08-21 11:06:17
32 [报告]
发表于 2006-01-17 15:16 |只看该作者
把你的shell给贴一下吧

论坛徽章:
0
33 [报告]
发表于 2006-01-17 15:17 |只看该作者
按协议和端口分队列比较好,例如将80,21端口的访问放在高优先队列里,其它相对低,这样即使流量跑满,关键应用总是能占到更多带宽,对于使用者来说的感觉就是关键业务只慢了一点或者没感觉慢,而p2p等就非常非常慢。

论坛徽章:
0
34 [报告]
发表于 2006-01-17 15:22 |只看该作者
原帖由 colddawn 于 2006-1-17 15:17 发表
按协议和端口分队列比较好,例如将80,21端口的访问放在高优先队列里,其它相对低,这样即使流量跑满,关键应用总是能占到更多带宽,对于使用者来说的感觉就是关键业务只慢了一点或者没感觉慢,而p2p等就非常非常 ...


很容易死, 现在80的代理多的是,BT也是很厉害的! 我前段时间用debian + ipfilter + ipp2p + layer7发现效果不太好, 最后还是用openbsd + pf 然后再就我上面说的那样找最大的用户封它。

论坛徽章:
0
35 [报告]
发表于 2006-01-17 15:26 |只看该作者
原帖由 rainren 于 2006-1-17 15:11 发表


很多用户用不到50个, 一般20-30个左右, 当然bt, emule 等下载量大的用户不是。我现在只是查找并发连接最多的IP, 封最大的一个基本上网速就上去了! 再不行就封第二个最多的!


我这里全民bt,ed,迅雷,只好用了。
pass in on $int_if inet proto {tcp,udp} from <ip_bad> to any keep state (source-track rule, max-src-nodes 300,max-src-states 50) queue bad_int

论坛徽章:
0
36 [报告]
发表于 2006-01-17 15:27 |只看该作者
原帖由 剑心通明 于 2006-1-17 15:16 发表
把你的shell给贴一下吧



同问,刚好开始学习shell

论坛徽章:
0
37 [报告]
发表于 2006-01-17 15:29 |只看该作者
原帖由 rainren 于 2006-1-17 15:22 发表


很容易死, 现在80的代理多的是,BT也是很厉害的! 我前段时间用debian + ipfilter + ipp2p + layer7发现效果不太好, 最后还是用openbsd + pf 然后再就我上面说的那样找最大的用户封它。



恩,我用ntop观察流量,发现走80端口的竟然占多数。最后还是靠限制连接数解决了。

论坛徽章:
0
38 [报告]
发表于 2006-01-17 17:14 |只看该作者
限制单IP连接有好几个参数,不过占用CPU处理时间,人多上网防火墙处理包效率不高的话会使网速慢下来!

max-src-nodes 300,max-src-states 50这两用的很多,

还有如:max-src-conn
max-src-conn-rate

这两个参数的效果也很好!具体看看pf.conf的说明, 这样比看pf的faq更能写好规则!

[ 本帖最后由 rainren 于 2006-1-17 17:16 编辑 ]

论坛徽章:
0
39 [报告]
发表于 2006-01-17 17:24 |只看该作者
这里有一段说明你能更好的理解对每一个IP做限制:


http://www.bgnett.no/~peter/pf/en/long-firewall.html

http://www.bgnett.no/~peter/pf/en/long-firewall.html#BRUTEFORCE
Turning away the brutes
If you run a Secure Shell login service anywhere which is accessible from the Internet, I'm sure you've seen things like these in your authentication logs:

Sep 26 03:12:34 skapet sshd[25771]: Failed password for root from
200.72.41.31 port 40992 ssh2
Sep 26 03:12:34 skapet sshd[5279]: Failed password for root from
200.72.41.31 port 40992 ssh2
Sep 26 03:12:35 skapet sshd[5279]: Received disconnect from
200.72.41.31: 11: Bye Bye
Sep 26 03:12:44 skapet sshd[29635]: Invalid user admin from
200.72.41.31
Sep 26 03:12:44 skapet sshd[24703]: input_userauth_request:
invalid user admin
Sep 26 03:12:44 skapet sshd[24703]: Failed password for invalid user
admin from 200.72.41.31 port 41484 ssh2
Sep 26 03:12:44 skapet sshd[29635]: Failed password for invalid user
admin from 200.72.41.31 port 41484 ssh2
Sep 26 03:12:45 skapet sshd[24703]: Connection closed by 200.72.41.31
Sep 26 03:13:10 skapet sshd[11459]: Failed password for root from
200.72.41.31 port 43344 ssh2
Sep 26 03:13:10 skapet sshd[7635]: Failed password for root from
200.72.41.31 port 43344 ssh2
Sep 26 03:13:10 skapet sshd[11459]: Received disconnect from
200.72.41.31: 11: Bye Bye
Sep 26 03:13:15 skapet sshd[31357]: Invalid user admin from 200.72.41.31
Sep 26 03:13:15 skapet sshd[10543]: input_userauth_request: invalid
user admin
Sep 26 03:13:15 skapet sshd[10543]: Failed password for invalid user
admin from 200.72.41.31 port 43811 ssh2
Sep 26 03:13:15 skapet sshd[31357]: Failed password for invalid user
admin from 200.72.41.31 port 43811 ssh2
Sep 26 03:13:15 skapet sshd[10543]: Received disconnect from
200.72.41.31: 11: Bye Bye
Sep 26 03:13:25 skapet sshd[6526]: Connection closed by 200.72.41.31It gets repetetive after that. This is what a brute force attack looks like. Essentially somebody, or more likely, a cracked computer somewhere, is trying by brute force to find a combination of user name and password which will let them into your system.

The simplest response would be to write a pf.conf rule which blocks all access. This leads to another class of problems, including what you do in order to let people with legitimate business on your system access it anyway. You might consider moving the service to some other port, but then again, the ones flooding you on port 22 would probably be able to scan their way to port 22222 for a repeat performance.

Since OpenBSD 3.7, PF has offered a slightly more elegant solution. You can write your pass rules so they maintain certain limits on what connecting hosts can do. For good measure, you can banish violators to a table of addresses which which you deny some or all access. You can even choose to drop all existing connections from machines which overreach your limits, if you like. Here's how it's done:

Now first set up the table. In your tables section, add

table <bruteforce> persistThen somewhere fairly early in your rule set you set up to block from the bruteforcers

block quick from <bruteforce>And finally, your pass rule.

pass inet proto tcp from any to $int_if:network port $tcp_services \
        flags S/SA keep state \
        (max-src-conn 100, max-src-conn-rate 15/5, \
         overload <bruteforce> flush global)This is rather similar to what we've seen before, isn't it? In fact, the first part is identical to the one we constructed earlier. The part in brackets is the new stuff which will ease your network load even further.

max-src-conn is the number of simultaneous connections you allow from one host. In this example, I've set it at 100, in your setup you may want a slightly higher or lower value.

max-src-conn-rate is the rate of new connections allowed from any single host, here 15 connections per 5 seconds. Again, you are the one to judge what suits your setup.

overload <bruteforce> means that any host which exceeds these limits gets its address added to the table bruteforce. Our rule set blocks all traffic from addresses in the bruteforce table.

finally, flush global says that when a host reaches the limit, that host's connections will be terminated (flushed). The global part says that for good measure, this applies to connections which match other pass rules too.

The effect is dramatic. My bruteforcers more often than not end up with "Fatal: timeout before authentication" messages, which is exactly what we want.

Once again, please keep in mind that this example rule is intended mainly as an illustration. It is not unlikely that your network's needs are better served by rather different rules or combinations of rules.

If, for example, you want to allow a generous number of connections in general, but would like to be a little more tight fisted when it comes to ssh, you could supplement the rule above with something like one early on in your rule set:

pass quick proto { tcp, udp } from any to any port ssh \
        flags S/SA keep state \
        (max-src-conn 15, max-src-conn-rate 5/3, \
        overload <bruteforce> flush global)You should be able to find the set of parameters which is just right for your situation by reading the relevant man pages and the PF User Guide, and perhaps a bit of experimentation.

论坛徽章:
0
40 [报告]
发表于 2006-01-17 17:25 |只看该作者
原帖由 rainren 于 2006-1-17 15:22 发表


很容易死, 现在80的代理多的是,BT也是很厉害的! 我前段时间用debian + ipfilter + ipp2p + layer7发现效果不太好, 最后还是用openbsd + pf 然后再就我上面说的那样找最大的用户封它。


代理是多,但p2p软件走http代理是很难实现的,再加上并发80端口限制的话,效果很不错的,用l7分析会导致网关服务器负载过高,你跑死并不一定是流量满了,更大的原因是网关自己处理不过来了。如果是找流量和并发大的那你的服务已经算是出问题中断过了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP