用同一台PC的两个网口实现Iperf的server端和client端

来源:互联网 发布:衣洛熙反串我知女人心 编辑:程序博客网 时间:2024/04/29 22:56

有时候需要发包,仅仅需要一定速率的流量,并不需要关心收到报文的大小,一个好用的开源软件发包工具并不好找,iperf发包很方便,但是一般需要两台电脑,分别作为server端和client端,如果使用一个PC的两个端口分别作为Iperf的Server端和Client端,只需要一台电脑,作为一个可携带的发包工具,会大大方便携带与使用。


将一台电脑的两个端口分别配置为不同的网段,如下:

ifconfig eth2 10.50.0.1/24ifconfig eth3 10.50.1.1/24
通过NAT实现IP源IP和目的IP转换:

# nat source IP 10.50.0.1 -> 10.60.0.1 when going to 10.60.1.1iptables -t nat -A POSTROUTING -s 10.50.0.1 -d 10.60.1.1 -j SNAT --to-source 10.60.0.1# nat inbound 10.60.0.1 -> 10.50.0.1iptables -t nat -A PREROUTING -d 10.60.0.1 -j DNAT --to-destination 10.50.0.1# nat source IP 10.50.1.1 -> 10.60.1.1 when going to 10.60.0.1iptables -t nat -A POSTROUTING -s 10.50.1.1 -d 10.60.0.1 -j SNAT --to-source 10.60.1.1# nat inbound 10.60.1.1 -> 10.50.1.1iptables -t nat -A PREROUTING -d 10.60.1.1 -j DNAT --to-destination 10.50.1.1

配置路由和ARP

ip route add 10.60.1.1 dev eth2arp -i eth2 -s 10.60.1.1 00:1B:21:C1:F6:0F # eth3's mac addressip route add 10.60.0.1 dev eth3 arp -i eth3 -s 10.60.0.1 00:1B:21:C1:F6:0E # eth2's mac address

检查网络

ping 10.60.1.1

运行iperf

# server./iperf -B 10.50.1.1 -s# client: your destination is the other end's fake address./iperf -B 10.50.0.1 -c 10.60.1.1 -t 60 -i 10

TCPDUMP检查

tcpdump -nn -i eth2 -c 500

0 0
原创粉丝点击