在我的机器上,我希望只有50%的数据包能够收到。
我正在使用centOS 5.5。
为此,我在网上search。 我得到了IPtables。 我使用了IPtables的随机补丁。
命令
sudo iptables -A INPUT -p icmp --icmp-type echo-request -m random --average 50 -j DROP
产量
iptables v1.3.5: Couldn't load match `random':/lib64/iptables/libipt_random.so: cannot open shared object file: No such file or directory Try `iptables -h' or 'iptables --help' for more information.
但上面显示,图书馆失踪。
那么,我怎样才能放下50%的数据包呢? 请纠正我的上述方法或build议新的方法。
告诉我如何将这些库添加到IPtables现有的包中。 [我试过,但是这些图书馆没有在互联网上find]
编辑1
我还需要logging丢弃的数据包,所以我改变了我的iptables规则集,如下所示:
iptables -L -n -v输出是[这是在系统1上运行]
Chain INPUT (policy ACCEPT 1875K packets, 114M bytes) pkts bytes target prot opt in out source destination 23 2392 random_drops icmp -- * * 0.0.0.0/0 0.0.0.0/0 statistic mode random probability 0.500000 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 2121K packets, 206M bytes) pkts bytes target prot opt in out source destination Chain random_drops (1 references) pkts bytes target prot opt in out source destination 23 2392 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4 prefix `dropped randomly: ' 23 2392 DROP all -- * * 0.0.0.0/0 0.0.0.0/0
然后我运行一个脚本(这个脚本在两个实例上运行在系统2上以创build更多的stream量)
while [ 1 ]; do rsh abcd pwd; done
在两个系统上。 但是没有形成日志。
我错过了什么?
CentOS 5.5没有预安装ipt_random和ipt_statistic模块。 你可能会恢复到CentosALT仓库 (原谅我的俄罗斯),并从那里使用随时编译的统计模块:
wget http://centos.alt.ru/repository/centos/5/x86_64/centalt-release-5-3.noarch.rpm # [...] rpm -Uvh centalt-release*rpm # [...] yum install ipt_statistic
并运行
sudo iptables -A INPUT -p icmp --icmp-type echo-request -m statistic --mode random --probability 0.50 -j DROP
应该产生你想要的规则。
来自Netem文档的注意事项:
注意事项
在本地使用丢失(不在网桥或路由器上)时,将丢失报告给上层协议。 这可能会导致TCP重新发送,并performance得好像没有任何损失。 当testing协议响应丢失时,最好在网桥或路由器上使用netem
虽然这显然不适用,只要你只是在input链DROPping。
这是一个内核configuration问题。 参见iptables-extensions(8) ,它解释了statistic模块:
iptables ... -m statistic --mode random --probability 0.5 ...
(根据需要填写)。
这是内核configurationCONFIG_NETFILTER_XT_MATCH_STATISTIC ,在这里设置为模块(Fedora 18,kernel-3.8.3-201.fc18.x86_64,iptables-1.4.16.2-5.fc18.x86_64)。 iptables userland可执行文件没有匹配的ipt_statistic共享对象。