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


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

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM