參考

FreeBSD中 ipfw的限速由dummynet來完成

有兩個選項 pipe 以及queue

pipe規定實際能用到的頻寬上限

#ipfw pipe 1 config 30KByte/s

#ipfw add pipe 1 ip from 192.168.0.0/24 to any

上面是限制從192.168.0.0/24到其他地方的速度為30KByte/s

 

queue的用法讓限速各具彈性,將packets導入pipe,依據設定給予一定比例的頻寬

#ipfw pipe 1 config bw 30KByte/s

#ipfw queue 1 config pipe 1 weight 10    //weight預設值1
#ipfw queue 2 config pipe 1 weight 20
#ipfw queue 3 config pipe 1 weight 30
#ipfw queue 4 config pipe 1 weight 40

#ipfw add 10 queue 1 from any to 192.168.1.1 http
#ipfw add 20 queue 2 from any to 192.168.1.2 http
#ipfw add 30 queue 3 from any to 192.168.1.3 http
#ipfw add 40 queue 4 from any to 192.168.1.4 http

上面的規則共享30KByte/s

10 / (10+20+30+40) * 30 = 3 KByte/s
20 / (10+20+30+40) * 30 = 6 KByte/s
30 / (10+20+30+40) * 30 = 9 KByte/s
40 / (10+20+30+40) * 30 = 12 KByte/s

以上為每個能使用的最大頻寬

但當192.168.1.1和192.168.1.3沒有在傳輸時

20 / (20+40) * 30 = 10 KByte/s

40 / (20+40) * 30 = 20 KByte/s

mask:[參考]

用處是,將 mask 過後相同的 ip/port 放在同一個 bucket 裡處
理。如果不特別指定時,mask 是 all bits 0, 也就是大家全部共
用一個bucket。 0xffffffff則是說我們要針對每個 host 給
予一個bucket, 分開使用 56/448k 的pipe。若內部只用到了
192.168.2.x 的ip, 事實上用0x000000ff 就可以達到相同的效果。
當然總量還是受到實際上的線路限制。

如果你有一台FTP server,想限速每個client的下載速度

ipfw pipe 50 config mask dst-ip 0x000000ff bw 25Kbit/s
ipfw add 100 pipe 50 src-port 20-21

文章標籤
全站熱搜
創作者介紹
創作者 slinbody 的頭像
slinbody

495884965

slinbody 發表在 痞客邦 留言(0) 人氣(445)