免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6278 | 回复: 9
打印 上一主题 下一主题

[OpenBSD] OpenBSD PF 单个IP限速 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-05-11 20:23 |只看该作者 |倒序浏览
做了一些网关, 一直是iptables + tc才能对网内每一个IP 限速! 用pf来做有点困难. 参考网上找到的许多规则, 实验了一些, 成了下面的规则, 各位可试验, 贴些自己的pf规则技巧, 让我也受益一些!





  1. ext_if="pppoe0"
  2. int_if="fxp1"

  3. set state-policy if-bound
  4. set block-policy return
  5. set optimization aggressive

  6. scrub in all

  7. altq on $ext_if hfsc bandwidth 512Kb queue { u1, u2, u3, u4, u5, u6, u7, u8, u9, u10, u11, u12, u13, u14, u15, u16, u17, u18, u19, u20, u21, u22, u23, u24, u25, u26, u27, u28, u29, u30, uother }
  8. queue u1 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  9. queue u2 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  10. queue u3 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  11. queue u4 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  12. queue u5 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  13. queue u6 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  14. queue u7 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  15. queue u8 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  16. queue u9 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  17. queue u10 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  18. queue u11 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  19. queue u12 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  20. queue u13 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  21. queue u14 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  22. queue u15 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  23. queue u16 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  24. queue u17 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  25. queue u18 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  26. queue u19 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  27. queue u20 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  28. queue u21 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  29. queue u22 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  30. queue u23 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  31. queue u24 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  32. queue u25 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  33. queue u26 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  34. queue u27 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  35. queue u28 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  36. queue u29 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  37. queue u30 bandwidth 16Kb hfsc ( upperlimit 128Kb red )
  38. queue uother bandwidth 32Kb hfsc ( default upperlimit 128Kb )

  39. altq on $int_if hfsc bandwidth 2Mb queue{ c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30, other }
  40. queue c1 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  41. queue c2 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  42. queue c3 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  43. queue c4 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  44. queue c5 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  45. queue c6 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  46. queue c7 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  47. queue c8 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  48. queue c9 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  49. queue c10 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  50. queue c11 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  51. queue c12 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  52. queue c13 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  53. queue c14 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  54. queue c15 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  55. queue c16 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  56. queue c17 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  57. queue c18 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  58. queue c19 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  59. queue c20 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  60. queue c21 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  61. queue c22 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  62. queue c23 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  63. queue c24 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  64. queue c25 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  65. queue c26 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  66. queue c27 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  67. queue c28 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  68. queue c29 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  69. queue c30 bandwidth 64Kb hfsc( upperlimit 512Kb red )
  70. queue other bandwidth 80Kb hfsc( default upperlimit 128Kb)

  71. nat on $ext_if from $int_if:network to any -> ($ext_if)

  72. block all
  73. block quick inet6 all

  74. pass quick on lo0 all

  75. antispoof for $ext_if

  76. pass in on $ext_if inet proto tcp from any to ($ext_if) port ssh flags S/SA keep state

  77. pass in quick on $int_if inet from 192.168.1.2 to any keep state tag 192.168.1.2 queue c1
  78. pass out quick on $ext_if inet all keep state tagged 192.168.1.2 queue u1

  79. pass in quick on $int_if inet from 192.168.1.3 to any keep state tag 192.168.1.3 queue c2
  80. pass out quick on $ext_if inet all keep state tagged 192.168.1.3 queue u2

  81. pass in quick on $int_if inet from 192.168.1.4 to any keep state tag 192.168.1.4 queue c3
  82. pass out quick on $ext_if inet all keep state tagged 192.168.1.4 queue u3

  83. pass in quick on $int_if inet from 192.168.1.5 to any keep state tag 192.168.1.5 queue c4
  84. pass out quick on $ext_if inet all keep state tagged 192.168.1.5 queue u4

  85. pass in quick on $int_if inet from 192.168.1.6 to any keep state tag 192.168.1.6 queue c5
  86. pass out quick on $ext_if inet all keep state tagged 192.168.1.6 queue u5

  87. pass in quick on $int_if inet from 192.168.1.7 to any keep state tag 192.168.1.7 queue c6
  88. pass out quick on $ext_if inet all keep state tagged 192.168.1.7 queue u6

  89. pass in quick on $int_if inet from 192.168.1.8 to any keep state tag 192.168.1.8 queue c7
  90. pass out quick on $ext_if inet all keep state tagged 192.168.1.8 queue u7

  91. pass in quick on $int_if inet from 192.168.1.9 to any keep state tag 192.168.1.9 queue c8
  92. pass out quick on $ext_if inet all keep state tagged 192.168.1.9 queue u8

  93. pass in quick on $int_if inet from 192.168.1.10 to any keep state tag 192.168.1.10 queue c9
  94. pass out quick on $ext_if inet all keep state tagged 192.168.1.10 queue u9

  95. pass in quick on $int_if inet from 192.168.1.11 to any keep state tag 192.168.1.11 queue c10
  96. pass out quick on $ext_if inet all keep state tagged 192.168.1.11 queue u10

  97. pass in quick on $int_if inet from 192.168.1.12 to any keep state tag 192.168.1.12 queue c11
  98. pass out quick on $ext_if inet all keep state tagged 192.168.1.12 queue u11

  99. pass in quick on $int_if inet from 192.168.1.13 to any keep state tag 192.168.1.13 queue c12
  100. pass out quick on $ext_if inet all keep state tagged 192.168.1.13 queue u12

  101. pass in quick on $int_if inet from 192.168.1.14 to any keep state tag 192.168.1.14 queue c13
  102. pass out quick on $ext_if inet all keep state tagged 192.168.1.14 queue u13

  103. pass in quick on $int_if inet from 192.168.1.18 to any keep state tag 192.168.1.18 queue c14
  104. pass out quick on $ext_if inet all keep state tagged 192.168.1.18 queue u14

  105. pass in quick on $int_if inet from 192.168.1.19 to any keep state tag 192.168.1.19 queue c15
  106. pass out quick on $ext_if inet all keep state tagged 192.168.1.19 queue u15

  107. pass in quick on $int_if inet from 192.168.1.20 to any keep state tag 192.168.1.20 queue c16
  108. pass out quick on $ext_if inet all keep state tagged 192.168.1.20 queue u16

  109. pass in quick on $int_if inet from 192.168.1.21 to any keep state tag 192.168.1.21 queue c17
  110. pass out quick on $ext_if inet all keep state tagged 192.168.1.21 queue u17

  111. pass in quick on $int_if inet from 192.168.1.22 to any keep state tag 192.168.1.22 queue c18
  112. pass out quick on $ext_if inet all keep state tagged 192.168.1.22 queue u18

  113. pass in quick on $int_if inet from 192.168.1.23 to any keep state tag 192.168.1.23 queue c19
  114. pass out quick on $ext_if inet all keep state tagged 192.168.1.23 queue u19

  115. pass in quick on $int_if inet from 192.168.1.24 to any keep state tag 192.168.1.24 queue c20
  116. pass out quick on $ext_if inet all keep state tagged 192.168.1.24 queue u20

  117. pass in quick on $int_if inet from 192.168.1.25 to any keep state tag 192.168.1.25 queue c21
  118. pass out quick on $ext_if inet all keep state tagged 192.168.1.25 queue u21

  119. pass in quick on $int_if inet from 192.168.1.26 to any keep state tag 192.168.1.26 queue c22
  120. pass out quick on $ext_if inet all keep state tagged 192.168.1.26 queue u22

  121. pass in quick on $int_if inet from 192.168.1.27 to any keep state tag 192.168.1.27 queue c23
  122. pass out quick on $ext_if inet all keep state tagged 192.168.1.27 queue u23

  123. pass in quick on $int_if inet from 192.168.1.28 to any keep state tag 192.168.1.28 queue c24
  124. pass out quick on $ext_if inet all keep state tagged 192.168.1.28 queue u24

  125. pass in quick on $int_if inet from 192.168.1.29 to any keep state tag 192.168.1.29 queue c25
  126. pass out quick on $ext_if inet all keep state tagged 192.168.1.29 queue u25

  127. pass in quick on $int_if inet from 192.168.1.30 to any keep state tag 192.168.1.30 queue c26
  128. pass out quick on $ext_if inet all keep state tagged 192.168.1.30 queue u26





复制代码

论坛徽章:
0
2 [报告]
发表于 2006-05-13 18:59 |只看该作者
这个在PF上配置,总显得比较繁琐。

论坛徽章:
0
3 [报告]
发表于 2006-05-14 01:33 |只看该作者
pf.conf 不能在自动生成一些相似行! iptables规则可shell编程。

论坛徽章:
0
4 [报告]
发表于 2006-05-15 23:26 |只看该作者
pf规则算很灵活了。
另外,做nat的话,ipfw/natd 跟pf没得比。

论坛徽章:
0
5 [报告]
发表于 2006-05-16 16:50 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
6 [报告]
发表于 2006-05-16 17:56 |只看该作者
老大
iptables可以控制mac地址来限制上网需求不?

论坛徽章:
0
7 [报告]
发表于 2008-09-09 15:36 |只看该作者

回复 #1 rainren 的帖子

这个pf太那个了吧,好麻烦啊,要是能按照地址列表限速就舒服些了

论坛徽章:
0
8 [报告]
发表于 2009-03-26 19:24 |只看该作者
是不是太麻烦了.要是带个300台机子.
那得写多少规则.

论坛徽章:
2
狮子座
日期:2013-08-26 15:25:32金牛座
日期:2013-09-05 15:45:36
9 [报告]
发表于 2009-03-26 20:16 |只看该作者
可以用table吗

论坛徽章:
0
10 [报告]
发表于 2009-03-26 20:59 |只看该作者

PF

有写好的或教程吗///
QQ:358340779
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP