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

原文鏈接:https://www.cnblogs.com/zafu/p/9515085.html

 

有時候需要發包,僅僅需要一定速率的流量,並不需要關心收到報文的大小,一個好用的開源軟件發包工具並不好找,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.  

     

  4.  

    # nat inbound 10.60.0.1 -> 10.50.0.1

  5.  

    iptables -t nat -A PREROUTING -d 10.60.0.1 -j DNAT --to-destination 10.50.0.1

  6.  

     

  7.  

    # nat source IP 10.50.1.1 -> 10.60.1.1 when going to 10.60.0.1

  8.  

    iptables -t nat -A POSTROUTING -s 10.50.1.1 -d 10.60.0.1 -j SNAT --to-source 10.60.1.1

  9.  

     

  10.  

    # nat inbound 10.60.1.1 -> 10.50.1.1

  11.  

    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.  

     

  4.  

    ip route add 10.60.0.1 dev eth3

  5.  

    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.  

     

  4.  

    # client: your destination is the other end's fake address

  5.  

    ./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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章