用同一台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

 

posted @   rebeca8  阅读(5275)  评论(1编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示