上海古都建筑设计集团,上海办公室装修设计公司,上海装修公司高质量的内容分享社区,上海装修公司我们不是内容生产者,我们只是上海办公室装修设计公司内容的搬运工平台

iperf3指定网卡测试 --bind-dev参数详解

guduadmin251月前

本文目录

  • 1、新老版本iperf3(iperf3 3.13 vs. iperf3 3.9)参数更新
  • 2、直接看结论
  • 3、--bind-dev dev使用详解
  • 4、-B hostIP[%dev]或者 --bind hostIP[%dev]的方式

    最新安装上了iperf3 最新的3.13版本,发现多了一个参数的支持–bind-dev。关注到这个参数的一定会知道老版本的iperf3里有一个-B的参数,可以在多IP的主机上指定使用哪个IP进行测试。本博客有过具体的分析,详细见iPerf3 -B参数详细图文分析

    1、新老版本iperf3(iperf3 3.13 vs. iperf3 3.9)参数更新

    • 老版本对-B参数的说明:

      通过指定ip地址来选择发送的端口,但我们能过上面的详细分析可知道,这个-B仅仅能指定通过哪个IP地址进行发送报文,并不能通过这个参数改变发送报文的物理网卡,主机通过哪个物理网卡发送数据,最终还是取决于主机的路由表(对于拥有多个属于同一个IP子网的网卡的主机有这个问题)。如果需要改变发送的物理网卡,我们还需要通过改变路由表项的matrix设置,来保证报文从指定的端口发送出去。

             -B, --bind host
                    bind to the specific interface associated with address host.
      
      • 新版本对-B参数以及新增加的–bind-dev的说明:

        新版本增加了指定物理网卡的参数,有二种方式:

      • 通过–bind-dev 跟上一个网卡名字的方式(ifconfig显示出来的网卡名字)显性的指定从哪个物理网卡进行发送,
      • 通过-B hostIP[%dev]或者 --bind hostIP[%dev]的方式,用[]里的可先参数的方式进行指定。
               -B, --bind host[%dev]
                      bind  to the specific interface associated with address host.  If an optional interface is specified, it is treated as a shortcut for --bind-dev dev.  Note that a percent sign and inter‐
                      face device name are required for IPv6 link-local address literals.
               --bind-dev dev
                      bind to the specified network interface.  This option uses SO_BINDTODEVICE, and may require root permissions.  (Available on Linux and possibly other systems.)
        

        2、直接看结论

        如果你不想看详细过程,那么可以直接看以下结论:

        1. 指定物理网卡则可以让主机从指定的物理网卡进行发送
        2. 指定物理网卡后,会自动使用物理网卡对应的IP地址进行发送

        3、–bind-dev dev使用详解

        1. 我们看一下,本机有二张网卡,属于同一个子网的IP地址,分别为eno1, enp2s0,对应的IP地址分别为192.168.3.238和192.168.3.107。在开始测试前,TX的报文数量分别为1.2G和370.4G。
        2. 使用iperf3 --bind-dev命令,通过enp2s0进行发包1.09Gbytes进行测试

          完成测试后,再次使用ifconfig命令查看,可以看到eno1网卡的TX数据发送量还是保持在1.2GB没有变化,而enp2s0的TX数据发送量从370.4G增长到371.7G说明数据是从enp2s0网卡发送的。

        3. 反过来通过iperf3 --bind-dev命令,通过eno1进行发包1.09Gbytes进行测试,我们则会发现: 完成测试后,再次使用ifconfig命令查看,可以看到enp2s0网卡的TX数据发送量还是保持在371.7GB没有变化,而eno1的TX数据发送量从1.2G增长到2.4G说明数据是从eno1网卡发送的。

        结论,直接指定物理网卡,则可以自动切换为指定物理网卡的IP地址进行发送。

        xxx@xxx-pc:~/iperf3/iperf$ ifconfig
        eno1: flags=4163  mtu 1500
                inet 192.168.3.238  netmask 255.255.255.0  broadcast 192.168.3.255
                inet6 fe80::a6fc:b416:ea9c:df2f  prefixlen 64  scopeid 0x20
                ether 8c:dc:d4:41:8b:ac  txqueuelen 1000  (以太网)
                RX packets 369667  bytes 26117275 (26.1 MB)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 807538  bytes 1224949754 (1.2 GB)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
                device interrupt 20  memory 0xf7f00000-f7f20000
        enp2s0: flags=4163  mtu 1500
                inet 192.168.3.107  netmask 255.255.255.0  broadcast 192.168.3.255
                inet6 fe80::98ed:685c:da1d:183e  prefixlen 64  scopeid 0x20
                ether a0:36:9f:56:95:be  txqueuelen 1000  (以太网)
                RX packets 7713629  bytes 1981189364 (1.9 GB)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 248973591  bytes 370498351533 (370.4 GB)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
                device memory 0xf7d00000-f7dfffff
        lo: flags=73  mtu 65536
                inet 127.0.0.1  netmask 255.0.0.0
                inet6 ::1  prefixlen 128  scopeid 0x10
                loop  txqueuelen 1000  (本地环回)
                RX packets 17648  bytes 2096944 (2.0 MB)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 17648  bytes 2096944 (2.0 MB)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        
        xxx@xxx-pc:~/iperf3/iperf$ /usr/local/bin/iperf3 -c 192.168.3.60 --bind-dev enp2s0
        我们从服务端可以看到,收到来自己192.168.3.107的1.09G的报文。
        -----------------------------------------------------------
        Server listening on 5201
        -----------------------------------------------------------
        Accepted connection from 192.168.3.107, port 47464
        [  5] local 192.168.3.60 port 5201 connected to 192.168.3.107 port 47476
        [ ID] Interval           Transfer     Bitrate
        [  5]   0.00-1.00   sec  92.6 MBytes   776 Mbits/sec
        [  5]   1.00-2.00   sec   112 MBytes   940 Mbits/sec
        [  5]   2.00-3.00   sec   112 MBytes   940 Mbits/sec
        [  5]   3.00-4.00   sec   112 MBytes   940 Mbits/sec
        [  5]   4.00-5.00   sec   112 MBytes   940 Mbits/sec
        [  5]   5.00-6.00   sec   112 MBytes   940 Mbits/sec
        [  5]   6.00-7.00   sec   112 MBytes   940 Mbits/sec
        [  5]   7.00-8.00   sec   112 MBytes   941 Mbits/sec
        [  5]   8.00-9.00   sec   112 MBytes   939 Mbits/sec
        [  5]   9.00-10.00  sec   112 MBytes   941 Mbits/sec
        [  5]  10.00-10.17  sec  19.5 MBytes   941 Mbits/sec
        - - - - - - - - - - - - - - - - - - - - - - - - -
        [ ID] Interval           Transfer     Bitrate
        [  5]   0.00-10.17  sec  1.09 GBytes   924 Mbits/sec                  receiver
        -----------------------------------------------------------
        
        xxx@xxx-pc:~/iperf3/iperf$ ifconfig
        eno1: flags=4163  mtu 1500
                inet 192.168.3.238  netmask 255.255.255.0  broadcast 192.168.3.255
                inet6 fe80::a6fc:b416:ea9c:df2f  prefixlen 64  scopeid 0x20
                ether 8c:dc:d4:41:8b:ac  txqueuelen 1000  (以太网)
                RX packets 371228  bytes 26246399 (26.2 MB)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 807585  bytes 1224955508 (1.2 GB)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
                device interrupt 20  memory 0xf7f00000-f7f20000
        enp2s0: flags=4163  mtu 1500
                inet 192.168.3.107  netmask 255.255.255.0  broadcast 192.168.3.255
                inet6 fe80::98ed:685c:da1d:183e  prefixlen 64  scopeid 0x20
                ether a0:36:9f:56:95:be  txqueuelen 1000  (以太网)
                RX packets 8073124  bytes 2004918105 (2.0 GB)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 249795878  bytes 371728640852 (371.7 GB)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
                device memory 0xf7d00000-f7dfffff
        
        xxx@xxx-pc:~/iperf3/iperf$ /usr/local/bin/iperf3 -c 192.168.3.60 --bind-dev eno1
        我们从服务端可以看到,收到来自己192.168.3.238的1.09G的报文。
        Accepted connection from 192.168.3.238, port 45136
        [  5] local 192.168.3.60 port 5201 connected to 192.168.3.238 port 45142
        [ ID] Interval           Transfer     Bitrate
        [  5]   0.00-1.00   sec  95.5 MBytes   801 Mbits/sec
        [  5]   1.00-2.00   sec   111 MBytes   934 Mbits/sec
        [  5]   2.00-3.00   sec   111 MBytes   934 Mbits/sec
        [  5]   3.00-4.00   sec   111 MBytes   934 Mbits/sec
        [  5]   4.00-5.00   sec   111 MBytes   934 Mbits/sec
        [  5]   5.00-6.00   sec   111 MBytes   934 Mbits/sec
        [  5]   6.00-7.00   sec   111 MBytes   934 Mbits/sec
        [  5]   7.00-8.00   sec   111 MBytes   934 Mbits/sec
        [  5]   8.00-9.00   sec   111 MBytes   934 Mbits/sec
        [  5]   9.00-10.00  sec   111 MBytes   934 Mbits/sec
        [  5]  10.00-10.14  sec  15.9 MBytes   934 Mbits/sec
        - - - - - - - - - - - - - - - - - - - - - - - - -
        [ ID] Interval           Transfer     Bitrate
        [  5]   0.00-10.14  sec  1.09 GBytes   921 Mbits/sec                  receiver
        xxx@xxx-pc:~/iperf3/iperf$ ifconfig
        demo-oai: flags=4099  mtu 1500
                inet 192.168.70.129  netmask 255.255.255.192  broadcast 192.168.70.191
                ether 02:42:11:7b:67:e4  txqueuelen 0  (以太网)
                RX packets 0  bytes 0 (0.0 B)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 0  bytes 0 (0.0 B)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        docker0: flags=4099  mtu 1500
                inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255
                ether 02:42:bf:65:22:bd  txqueuelen 0  (以太网)
                RX packets 0  bytes 0 (0.0 B)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 0  bytes 0 (0.0 B)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        eno1: flags=4163  mtu 1500
                inet 192.168.3.238  netmask 255.255.255.0  broadcast 192.168.3.255
                inet6 fe80::a6fc:b416:ea9c:df2f  prefixlen 64  scopeid 0x20
                ether 8c:dc:d4:41:8b:ac  txqueuelen 1000  (以太网)
                RX packets 726265  bytes 51096987 (51.0 MB)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 1614509  bytes 2449795540 (2.4 GB)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
                device interrupt 20  memory 0xf7f00000-f7f20000
        enp2s0: flags=4163  mtu 1500
                inet 192.168.3.107  netmask 255.255.255.0  broadcast 192.168.3.255
                inet6 fe80::98ed:685c:da1d:183e  prefixlen 64  scopeid 0x20
                ether a0:36:9f:56:95:be  txqueuelen 1000  (以太网)
                RX packets 8080367  bytes 2005367711 (2.0 GB)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 249808572  bytes 371729998079 (371.7 GB)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
                device memory 0xf7d00000-f7dfffff
        

        4、-B hostIP[%dev]或者 --bind hostIP[%dev]的方式

        看起来,会检查指定的IP地址和物理网卡的绑定关系,如果不一至就会出错。(尚未分析过原因为何会出错,因为原先不指定[%dev]时,主机程序不会 IP地址和物理网卡的绑定关系,主机总是使用指定的IP,但却按照路由表决定由哪些网卡进行发送)。网卡配置情况,路由表项,如下所示。

        xxx@xxx-pc:~/iperf3/iperf$ /usr/local/bin/iperf3 -c 192.168.3.60 -B 192.168.3.238%eno1------通过网瞳eno1发送
        xxx@xxx-pc:~/iperf3/iperf$ /usr/local/bin/iperf3 -c 192.168.3.60 -B 192.168.3.238%enp2s0----出错,连接超时
        xxx@xxx-pc:~/iperf3/iperf$ /usr/local/bin/iperf3 -c 192.168.3.60 -B 192.168.3.107%enp2s0---通过网卡enp2s0发送
        xxx@xxx-pc:~/iperf3/iperf$ /usr/local/bin/iperf3 -c 192.168.3.60 -B 192.168.3.107%eno1------出错,连接超时
        xxx@xxx-pc:~/iperf3/iperf$ ifconfig
        eno1: flags=4163  mtu 1500
                inet 192.168.3.238  netmask 255.255.255.0  broadcast 192.168.3.255
                inet6 fe80::a6fc:b416:ea9c:df2f  prefixlen 64  scopeid 0x20
                ether 8c:dc:d4:41:8b:ac  txqueuelen 1000  (以太网)
                RX packets 2143213  bytes 150333835 (150.3 MB)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 3228464  bytes 4899509947 (4.8 GB)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
                device interrupt 20  memory 0xf7f00000-f7f20000
        enp2s0: flags=4163  mtu 1500
                inet 192.168.3.107  netmask 255.255.255.0  broadcast 192.168.3.255
                inet6 fe80::98ed:685c:da1d:183e  prefixlen 64  scopeid 0x20
                ether a0:36:9f:56:95:be  txqueuelen 1000  (以太网)
                RX packets 8818872  bytes 2054024464 (2.0 GB)
                RX errors 0  dropped 0  overruns 0  frame 0
                TX packets 253112865  bytes 376654961590 (376.6 GB)
                TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
                device memory 0xf7d00000-f7dfffff
        xxx@xxx-pc:~/iperf3/iperf$ route
        内核 IP 路由表
        目标            网关            子网掩码        标志  跃点   引用  使用 接口
        default         _gateway        0.0.0.0         UG    100    0        0 enp2s0
        default         _gateway        0.0.0.0         UG    101    0        0 eno1
        link-local      0.0.0.0         255.255.0.0     U     1000   0        0 enp2s0
        172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
        192.168.3.0     0.0.0.0         255.255.255.0   U     100    0        0 enp2s0
        192.168.3.0     0.0.0.0         255.255.255.0   U     101    0        0 eno1
        192.168.70.128  0.0.0.0         255.255.255.192 U     0      0        0 demo-oai
        192.168.71.128  0.0.0.0         255.255.255.192 U     0      0        0 rfsim5g-public
        192.168.72.128  0.0.0.0         255.255.255.192 U     0      0        0 rfsim5g-traffic
        

网友评论

搜索
最新文章
热门文章
热门标签
 
 梦见理发是怎么回事  梦见杀羊  梦见被狗咬伤