1. 程式人生 > >用同一臺PC的兩個網口實現Iperf的server端和client端

用同一臺PC的兩個網口實現Iperf的server端和client端

header 只需要 select data- 檢查網絡 server 閱讀 fig -s

用同一臺PC的兩個網口實現Iperf的server端和client端

2015年10月20日 20:35:11 閱讀數:2943

有時候需要發包,僅僅需要一定速率的流量,並不需要關心收到報文的大小,一個好用的開源軟件發包工具並不好找,iperf發包很方便,但是一般需要兩臺電腦,分別作為server端和client端,如果使用一個PC的兩個端口分別作為Iperf的Server端和Client端,只需要一臺電腦,作為一個可攜帶的發包工具,會大大方便攜帶與使用。

將一臺電腦的兩個端口分別配置為不同的網段,如下:

  1. ifconfig eth2 10.50.0.1/24
  2. ifconfig eth3 10.50.1.1/24
通過NAT實現IP源IP和目的IP轉換:

  1. # nat source IP 10.50.0.1 -> 10.60.0.1 when going to 10.60.1.1
  2. iptables -t nat -A POSTROUTING -s 10.50.0.1 -d 10.60.1.1 -j SNAT --to-source 10.60.0.1
  3. # nat inbound 10.60.0.1 -> 10.50.0.1
  4. iptables -t nat -A PREROUTING -d 10.60.0.1 -j DNAT --to-destination 10.50.0.1
  5. # nat source IP 10.50.1.1 -> 10.60.1.1 when going to 10.60.0.1
  6. iptables -t nat -A POSTROUTING -s 10.50.1.1 -d 10.60.0.1 -j SNAT --to-source 10.60.1.1
  7. # nat inbound 10.60.1.1 -> 10.50.1.1
  8. iptables -t nat -A PREROUTING -d 10.60.1.1 -j DNAT --to-destination 10.50.1.1

配置路由和ARP

  1. ip route add 10.60.1.1 dev eth2
  2. arp -i eth2 -s 10.60.1.1 00:1B:21:C1:F6:0F # eth3‘s mac address
  3. ip route add 10.60.0.1 dev eth3
  4. arp -i eth3 -s 10.60.0.1 00:1B:21:C1:F6:0E # eth2‘s mac address

檢查網絡

ping 10.60.1.1

運行iperf

  1. # server
  2. ./iperf -B 10.50.1.1 -s
  3. # client: your destination is the other end‘s fake address
  4. ./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端