用同一臺PC的兩個網口實現Iperf的server端和client端
阿新 • • 發佈:2018-08-22
header 只需要 select data- 檢查網絡 server 閱讀 fig -s
用同一臺PC的兩個網口實現Iperf的server端和client端
2015年10月20日 20:35:11 閱讀數:2943有時候需要發包,僅僅需要一定速率的流量,並不需要關心收到報文的大小,一個好用的開源軟件發包工具並不好找,iperf發包很方便,但是一般需要兩臺電腦,分別作為server端和client端,如果使用一個PC的兩個端口分別作為Iperf的Server端和Client端,只需要一臺電腦,作為一個可攜帶的發包工具,會大大方便攜帶與使用。
將一臺電腦的兩個端口分別配置為不同的網段,如下:
- ifconfig eth2 10.50.0.1/24
- ifconfig eth3 10.50.1.1/24
- # nat source IP 10.50.0.1 -> 10.60.0.1 when going to 10.60.1.1
- iptables -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.1
- iptables -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.1
- iptables -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.1
- iptables -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 eth2
- arp -i eth2 -s 10.60.1.1 00:1B:21:C1:F6:0F # eth3‘s mac address
- ip 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
用同一臺PC的兩個網口實現Iperf的server端和client端