dev*_*sda 3 linux bash iptables centos packet-capture
在我的机器上,我希望只有 50% 的数据包会收到。
我正在开发 centOS 5.5。
为此,我在网上搜索。我得到了 IPtables。我使用了 IPtables 的随机补丁。
命令
sudo iptables -A INPUT -p icmp --icmp-type echo-request -m random --average 50 -j DROP
Run Code Online (Sandbox Code Playgroud)
输出
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.
Run Code Online (Sandbox Code Playgroud)
但上面表明该库丢失了。
然后,我怎样才能丢弃总数的 50% 数据包。请更正我的上述方法或建议新的方法。
告诉我如何将这些库添加到 IPtables 现有包中。[我试过了,但在互联网上找不到这些库]
编辑 1
我还需要记录丢弃的数据包,因此我更改了 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
Run Code Online (Sandbox Code Playgroud)
然后我运行一个脚本(该脚本在系统 2 上运行两个实例以创建更多流量)
while [ 1 ]; do
rsh a.b.c.d pwd;
done
Run Code Online (Sandbox Code Playgroud)
在两个系统上。但是没有形成日志。
我错过了什么?
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
Run Code Online (Sandbox Code Playgroud)
和跑步
sudo iptables -A INPUT -p icmp --icmp-type echo-request -m statistic --mode random --probability 0.50 -j DROP
Run Code Online (Sandbox Code Playgroud)
应该产生你想要的规则。
Netem 文档中的注释:
注意事项
当丢失在本地(不在网桥或路由器上)使用时,丢失将报告给上层协议。这可能会导致 TCP 重新发送并表现得好像没有丢失一样。在测试协议响应丢失时,最好在网桥或路由器上使用网络
尽管这显然不适用,只要您只是在 INPUT 链中进行 DROPping。
| 归档时间: |
|
| 查看次数: |
7730 次 |
| 最近记录: |