用同一台PC的兩個網口實現Iperf的server端和client端
有時候需要發包,僅僅需要一定速率的流量,並不需要關心收到報文的大小,一個好用的開源軟件發包工具並不好找,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.50.1.1 -t 60 -i 10(原來csdn上的連接有一定的問題,-c 10.60.1.1測試不通)
TCPDUMP檢查
tcpdump -nn -i eth2 -c 500