寻觅生命中的那一片浅草......

每日存档 四月 30th, 2010

Dynamic port forward:ssh -D

Bypass the Firewall with “ssh -Nf -D 10086 username@server”

all traffic coming to port 10086 on the client will be forwarded to the server

Great SSH!

iptables的妙用——条件限速

某些路由器具有所谓的流量控制中具有“惩罚性限速”的功能:(例如)192.168.1.100在120秒内平均速率超过100KB/S,那么把该IP
列入惩罚队列,惩罚队列速率是40KB/S.

其实,利用iptables的也可以实现类似的功能。脚本如下:

iptables -t mangle -N LMT
iptables -t mangle -N LMT2
iptables -t mangle -I FORWARD -d 192.168.1.100 -m length –length 128: -j LMT
iptables -t mangle -A LMT -m recent –rdest –name badguy –rcheck –seconds 60 -j LMT2
iptables -t mangle -A LMT -m limit –limit 100/sec –limit-burst 5000 -j RETURN
iptables -t mangle -A LMT -m recent –rdest –name badguy –set -j RETURN
iptables -t mangle -A LMT2 -m limit –limit 50/sec –limit-burst 5000 -j RETURN
iptables -t mangle -A LMT2 -j DROP
复制代码

上面代码是用limit限制计算速率,为了更准确,使用了数据包长度筛选: “-m length –length 128:”,这样更准确一点。
一般限制为100/s,按照数据包平均大小1000Bytes来算,大概就是100KB/S。
如果超出,限制变为50/sec,大约50KB/S。

当然,这只是一个示范性的例子了,其中limit模块也可以改用更为强大的hashlimit,hashsped等模块。
还可以用connlimit使用连接数作为限制条件。。。。。。。。。。
如果再把这些模块结合MARK和TC流量控制,就实现了某些路由器的所谓“条件限速”“P2P惩罚”等功能。

转载自:http://linux.chinaunix.net/bbs/thread-1156170-1-1.html

2010年四月
« 3月   5月 »
 1234
567891011
12131415161718
19202122232425
2627282930