|
|
发表于 2005-2-6 22:44:56
|
显示全部楼层
不知道用 iptables 的 -m limit 选项行不行,我倒是试了一下,觉得很奇怪,对于这个 limit 参数到底怎么用还是一知半解的。
比如,我写了这样一个脚本:
- #!/bin/bash
- # [/usr/local/sbin/]ipt04_limit.sh
- /sbin/modprobe ipt_MASQUERADE
- /sbin/modprobe iptable_nat
- /sbin/modprobe ip_conntrack
- /sbin/modprobe ip_conntrack_ftp
- /sbin/modprobe ip_nat_ftp
- iptables -F
- iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
- echo 1 > /proc/sys/net/ipv4/ip_forward
- iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # [1]
- iptables -A INPUT -m state --state NEW -i lo -j ACCEPT
- iptables -A INPUT -m state --state NEW -i ! ppp0 -j ACCEPT
- # iptables -A INPUT -i lo -j ACCEPT
- # iptables -A INPUT -i ! ppp0 -j ACCEPT
- iptables -A INPUT -p tcp --sport 80 -j ACCEPT # [2]: if not [1]
- # iptables -A INPUT -p tcp --sport 53 -j ACCEPT # [3]: FOR DNS responding
- iptables -A INPUT -p tcp --dport 21 -j ACCEPT
- iptables -A INPUT -p tcp --dport 20 -j ACCEPT
- iptables -A INPUT -p tcp --dport 80 -j LOG --log-prefix "APACHE: "
- iptables -A INPUT -p tcp --dport 80 -j ACCEPT
- iptables -A INPUT -p tcp --dport 3313 -j ACCEPT # FOR: skype
- iptables -A INPUT -j DROP
- iptables -A OUTPUT -o lo -j ACCEPT
- iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
- iptables -A OUTPUT -p udp --dport 53 -j ACCEPT # DNS udp
- iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
- iptables -A OUTPUT -p tcp -m limit --limit 50/s -j LOG --log-prefix "limit_rate: "
- iptables -A OUTPUT -p tcp -m limit --limit 50/s -j DROP
- iptables -A OUTPUT -p tcp -m limit --limit-burst 3 -j LOG --log-prefix "limit_brst: "
- iptables -A OUTPUT -p tcp -m limit --limit-burst 3 -j DROP
- iptables -A OUTPUT -p tcp --sport 6881 -j ACCEPT
- iptables -A OUTPUT -j DROP
- iptables -A FORWARD -s 192.168.0.0/24 -j ACCEPT
- iptables -A FORWARD -j DROP
复制代码
我的本意是限制在 50/s 的上传速率。最开始我设置的是 1/s,BT(Azureus) 的上传开到 50K/s,没有效果,于是我调整到 50/s,结果速度很快就降到了 0 并维持下去?
下一次,我将 BT 调整到 10K/s,重新刷新 iptables 规则(50/s),开始没有问题,然后将 BT 调整到 50K/S,结果又是马上降到 0 并维持下去?
是不是只要超过了,就完全禁止了? |
|