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

     

  • 相关阅读:
    python 输出时间格式化及前一天、前一秒时间
    python双色球选号生成
    python爬虫练习
    python爬虫之BeautifulSoup4介绍
    装饰器
    *args和**kwargs
    (二)python爬虫实例:猫眼电影TOP100榜并将电影信息写入到Excel(Excel列宽自适应)
    (一)python爬虫实例:猫眼电影TOP100榜并将电影信息写入到Excel
    python安装库时,pip install xxx下载慢以及超时失败的问题解决
    python之高阶函数map()reduce()filter()
  • 原文地址:https://www.cnblogs.com/zafu/p/9515085.html
Copyright © 2020-2023  润新知