Linux命令netstat/lsof/netperf安装、使用

一、netstat常用命令

netstat是一条用于显示网络状态和信息的命令。在Linux系统中,我们可以使用netstat命令来查看与网络相关的信息,例如网络连接、路由表、网络接口和多播组等。

常见的用法包括:

  1. 显示所有网络连接:
netstat -a

该命令将显示所有当前的网络连接,包括TCP、UDP和Unix域套接字。其中,“-a”表示显示所有的网络连接。

        2. 显示网络连接状态:

netstat -s
[root@localhost netperf-netperf-2.7.0]# netstat -s
Ip:
    240273 total packets received
    0 forwarded
    0 incoming packets discarded
    240181 incoming packets delivered
    296561 requests sent out
    40 dropped because of missing route
Icmp:
    6 ICMP messages received
    0 input ICMP message failed.
    ICMP input histogram:
        destination unreachable: 5
        echo requests: 1
    57 ICMP messages sent
    0 ICMP messages failed
    ICMP output histogram:
        destination unreachable: 56
        echo replies: 1
IcmpMsg:
        InType3: 5

该命令将汇总所有网络连接的状态,包括TCP、UDP和ICMP。

        3. 显示监听端口:

netstat -l
[root@localhost netperf-netperf-2.7.0]# netstat -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:epmd            0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN     
tcp        0      0 localhost:smtp          0.0.0.0:*               LISTEN  

该命令将列出所有正在监听的端口。其中,“-l”表示显示所有的监听端口。

        4. 显示特定协议连接情况:

netstat -p [protocol]
[root@localhost netperf-netperf-2.7.0]# netstat -p -t
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0     36 localhost.localdoma:ssh 192.168.6.1:54688       ESTABLISHED 1246/sshd: root@pts 
tcp        0      0 localhost:57201         localhost:epmd          ESTABLISHED 69970/beam          
tcp        0      0 localhost:epmd          localhost:57201         ESTABLISHED 69785/epmd          
tcp        0      0 localhost.localdoma:ssh 192.168.6.1:49949       ESTABLISHED 70851/sshd: root@pt 
[root@localhost netperf-netperf-2.7.0]# 
[root@localhost netperf-netperf-2.7.0]# netstat -p -u
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    

该命令将显示特定协议的连接情况,例如TCP或者UDP。可以通过“-p”参数指定要显示的协议。

        5. 显示路由表:

netstat -r

该命令将显示当前系统的路由表,包括目的地址、网关、网络接口和路由类型等。

需要注意的是,netstat命令只能显示当前系统的网络状态信息,而不能修改或者配置网络参数。如果需要修改网络参数,可以使用其他命令,例如ifconfig和route命令。

二、安装netstat

如果在你的Linux系统上未找到netstat命令,可能是因为该命令未安装在系统上。

在大多数基于Debian或Ubuntu的系统中,你可以使用以下命令来安装netstat:

sudo apt-get install net-tools

在基于Red Hat或CentOS的系统中,你可以使用以下命令来安装netstat:

sudo yum install net-tools

安装完成后,你应该能够在终端中使用netstat命令了。

三、lsof常用命令

lsof(list open files)是一个列出当前系统打开文件的工具,可以显示进程打开的文件列表,包括文件名、文件描述符、文件类型、文件状态、文件大小等信息。lsof是一款非常实用的系统管理工具,常用于定位文件锁定、资源占用或者查找进程打开的文件等任务。

使用lsof命令时,需要指定要查询的选项和参数。以下是一些主要的选项:

  • -p:指定要查询的进程号。
  • -u:指定要查询的用户。
  • -i:显示打开的网络套接字。
  • -c:指定进程名。
  • -n:直接使用数字IP地址,不进行反解查询。
  • -t:只显示进程号。

举个例子,如果你想查看进程号为1234打开的所有文件,可以执行以下命令:

lsof -p 1234

如果你想查看所有使用TCP连接的进程,可以执行以下命令:

sudo lsof -i tcp

需要注意的是,lsof需要root权限才能查询所有进程的信息。如果没有root权限,则只能查询当前用户的进程信息。

四、安装netperf

[root@localhost ~]# yum install netperf
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.bupt.edu.cn
 * epel: mirror-icn.yuki.net.uk
 * extras: mirrors.bupt.edu.cn
 * updates: mirrors.bupt.edu.cn
没有可用软件包 netperf。
错误:无须任何处理

如果 yum install netperf 未安装成功,你可以尝试下载源码编译安装:

  1. 下载 netperf 源码包

下载 netperf 源码包。例如:

curl -L https://codeload.github.com/HewlettPackard/netperf/zip/netperf-2.7.0 -o netperf.zip

        2. 解压安装包

unzip netperf.zip

        3. 编译安装

cd netperf-netperf-2.7.0/
./configure
make && make install

        4. 测试 netperf 是否安装成功

运行 netperf -h,如果能够正常输出帮助信息,则表明安装成功。

运行 netperf -H [远程服务器IP],测试远程服务器的网络吞吐量和延迟等性能指标。请将 [远程服务器IP] 替换为目标服务器的 IP 地址。

例如,运行 netperf -H 192.168.1.100,测试本机与 192.168.1.100 服务器之间的网络吞吐量和延迟等指标。

[root@localhost tool]# curl -L https://codeload.github.com/HewlettPackard/netperf/zip/netperf-2.7.0 -o netperf.zip
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 2028k    0 2028k    0     0  36201      0 --:--:--  0:00:57 --:--:--  143k
[root@localhost tool]# ls
netperf.zip
[root@localhost tool]# unzip netperf.zip 
-bash: unzip: 未找到命令
[root@localhost tool]# yum install unzip
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.bupt.edu.cn
 * epel: mirror-icn.yuki.net.uk
 * extras: mirrors.bupt.edu.cn
 * updates: mirrors.bupt.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 unzip.x86_64.0.6.0-24.el7_9 将被 安装
--> 解决依赖关系完成

依赖关系解决

============================================================================================================================================
 Package                       架构                           版本                                    源                               大小
============================================================================================================================================
正在安装:
 unzip                         x86_64                         6.0-24.el7_9                            updates                         172 k

事务概要
============================================================================================================================================
安装  1 软件包

总下载量:172 k
安装大小:369 k
Is this ok [y/d/N]: y
Downloading packages:
unzip-6.0-24.el7_9.x86_64.rpm                                                                                        | 172 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : unzip-6.0-24.el7_9.x86_64                                                                                               1/1 
  验证中      : unzip-6.0-24.el7_9.x86_64                                                                                               1/1 

已安装:
  unzip.x86_64 0:6.0-24.el7_9                                                                                                               

完毕!
[root@localhost tool]# ls
netperf.zip
[root@localhost tool]# unzip netperf.zip 
Archive:  netperf.zip
f46c0319851d85e135e46289fa484b01705af73e
   creating: netperf-netperf-2.7.0/
  inflating: netperf-netperf-2.7.0/AUTHORS  
  inflating: netperf-netperf-2.7.0/COPYING  
 extracting: netperf-netperf-2.7.0/ChangeLog  
  inflating: netperf-netperf-2.7.0/INSTALL  
  inflating: netperf-netperf-2.7.0/Makefile.am  
  inflating: netperf-netperf-2.7.0/Makefile.in  
 extracting: netperf-netperf-2.7.0/NEWS  
  inflating: netperf-netperf-2.7.0/README  
  inflating: netperf-netperf-2.7.0/README.aix  
  inflating: netperf-netperf-2.7.0/README.hpux  
  inflating: netperf-netperf-2.7.0/README.osx  
  inflating: netperf-netperf-2.7.0/README.ovms  
  inflating: netperf-netperf-2.7.0/README.solaris  
  inflating: netperf-netperf-2.7.0/README.vmware  
  inflating: netperf-netperf-2.7.0/README.windows  
  inflating: netperf-netperf-2.7.0/Release_Notes  
  inflating: netperf-netperf-2.7.0/acinclude.m4  
  inflating: netperf-netperf-2.7.0/aclocal.m4  
  inflating: netperf-netperf-2.7.0/autogen.sh  
  inflating: netperf-netperf-2.7.0/config.guess  
  inflating: netperf-netperf-2.7.0/config.h.in  
  inflating: netperf-netperf-2.7.0/config.sub  
  inflating: netperf-netperf-2.7.0/configure  
  inflating: netperf-netperf-2.7.0/configure.ac  
  inflating: netperf-netperf-2.7.0/depcomp  
   creating: netperf-netperf-2.7.0/doc/
  inflating: netperf-netperf-2.7.0/doc/Makefile.am  
  inflating: netperf-netperf-2.7.0/doc/Makefile.in  
   creating: netperf-netperf-2.7.0/doc/examples/
  inflating: netperf-netperf-2.7.0/doc/examples/Makefile.am  
  inflating: netperf-netperf-2.7.0/doc/examples/Makefile.in  
  inflating: netperf-netperf-2.7.0/doc/examples/arr_script  
  inflating: netperf-netperf-2.7.0/doc/examples/bloat.py  
  inflating: netperf-netperf-2.7.0/doc/examples/bloat.sh  
  inflating: netperf-netperf-2.7.0/doc/examples/find_max_burst.sh  
  inflating: netperf-netperf-2.7.0/doc/examples/mins_maxes.awk  
  inflating: netperf-netperf-2.7.0/doc/examples/netperf_by_flavor.py  
  inflating: netperf-netperf-2.7.0/doc/examples/netperf_by_quantum.py  
  inflating: netperf-netperf-2.7.0/doc/examples/netperf_interim_to_rrd.sh  
  inflating: netperf-netperf-2.7.0/doc/examples/packet_byte_script  
  inflating: netperf-netperf-2.7.0/doc/examples/post_proc.py  
  inflating: netperf-netperf-2.7.0/doc/examples/post_proc.sh  
  inflating: netperf-netperf-2.7.0/doc/examples/remote_hosts  
  inflating: netperf-netperf-2.7.0/doc/examples/runemomni.sh  
  inflating: netperf-netperf-2.7.0/doc/examples/runemomniagg2.sh  
  inflating: netperf-netperf-2.7.0/doc/examples/runemomniaggdemo.sh  
  inflating: netperf-netperf-2.7.0/doc/examples/runremomniaggdemo.sh  
  inflating: netperf-netperf-2.7.0/doc/examples/runremrandomniaggdemo.sh  
  inflating: netperf-netperf-2.7.0/doc/examples/sctp_stream_script  
  inflating: netperf-netperf-2.7.0/doc/examples/set_affinity.sh  
  inflating: netperf-netperf-2.7.0/doc/examples/snapshot_script  
  inflating: netperf-netperf-2.7.0/doc/examples/tcp_range_script  
  inflating: netperf-netperf-2.7.0/doc/examples/tcp_rr_script  
  inflating: netperf-netperf-2.7.0/doc/examples/tcp_stream_script  
  inflating: netperf-netperf-2.7.0/doc/examples/udp_rr_script  
  inflating: netperf-netperf-2.7.0/doc/examples/udp_stream_script  
  inflating: netperf-netperf-2.7.0/doc/examples/vrules.awk  
  inflating: netperf-netperf-2.7.0/doc/netperf.html  
  inflating: netperf-netperf-2.7.0/doc/netperf.info  
  inflating: netperf-netperf-2.7.0/doc/netperf.man  
  inflating: netperf-netperf-2.7.0/doc/netperf.pdf  
  inflating: netperf-netperf-2.7.0/doc/netperf.ps  
  inflating: netperf-netperf-2.7.0/doc/netperf.texi  
  inflating: netperf-netperf-2.7.0/doc/netperf.txt  
  inflating: netperf-netperf-2.7.0/doc/netperf.xml  
  inflating: netperf-netperf-2.7.0/doc/netperf_old.ps  
  inflating: netperf-netperf-2.7.0/doc/netserver.man  
  inflating: netperf-netperf-2.7.0/doc/omni_output_list.txt  
  inflating: netperf-netperf-2.7.0/doc/texinfo.tex  
 extracting: netperf-netperf-2.7.0/inet_ntop.c  
  inflating: netperf-netperf-2.7.0/install-sh  
   creating: netperf-netperf-2.7.0/m4/
   creating: netperf-netperf-2.7.0/m4/m4/
  inflating: netperf-netperf-2.7.0/m4/m4/salen.m4  
  inflating: netperf-netperf-2.7.0/m4/m4/sockaddrin6.m4  
  inflating: netperf-netperf-2.7.0/m4/m4/sockinttypes.m4  
  inflating: netperf-netperf-2.7.0/missing  
  inflating: netperf-netperf-2.7.0/mkinstalldirs  
  inflating: netperf-netperf-2.7.0/netperf.spec.in  
   creating: netperf-netperf-2.7.0/src/
  inflating: netperf-netperf-2.7.0/src/Makefile.am  
  inflating: netperf-netperf-2.7.0/src/Makefile.in  
  inflating: netperf-netperf-2.7.0/src/Makefile.uw  
   creating: netperf-netperf-2.7.0/src/NetPerfDir/
  inflating: netperf-netperf-2.7.0/src/NetPerfDir/inet_ntop.c  
  inflating: netperf-netperf-2.7.0/src/NetPerfDir/makefile  
  inflating: netperf-netperf-2.7.0/src/NetPerfDir/sources  
   creating: netperf-netperf-2.7.0/src/NetServerDir/
  inflating: netperf-netperf-2.7.0/src/NetServerDir/inet_ntop.c  
  inflating: netperf-netperf-2.7.0/src/NetServerDir/makefile  
  inflating: netperf-netperf-2.7.0/src/NetServerDir/sources  
  inflating: netperf-netperf-2.7.0/src/dirs  
  inflating: netperf-netperf-2.7.0/src/dscp.c  
  inflating: netperf-netperf-2.7.0/src/hist.h  
   creating: netperf-netperf-2.7.0/src/missing/
  inflating: netperf-netperf-2.7.0/src/missing/Makefile.am  
  inflating: netperf-netperf-2.7.0/src/missing/Makefile.in  
  inflating: netperf-netperf-2.7.0/src/missing/getaddrinfo.c  
  inflating: netperf-netperf-2.7.0/src/missing/getaddrinfo.h  
  inflating: netperf-netperf-2.7.0/src/missing/inet_ntop.c  
  inflating: netperf-netperf-2.7.0/src/missing/inttypes.h  
   creating: netperf-netperf-2.7.0/src/missing/m4/
 extracting: netperf-netperf-2.7.0/src/missing/m4/Makefile.am  
  inflating: netperf-netperf-2.7.0/src/missing/m4/Makefile.in  
  inflating: netperf-netperf-2.7.0/src/missing/m4/herrno.m4  
  inflating: netperf-netperf-2.7.0/src/missing/m4/in6addr.m4  
  inflating: netperf-netperf-2.7.0/src/missing/m4/salen.m4  
  inflating: netperf-netperf-2.7.0/src/missing/m4/sockaddrin6.m4  
  inflating: netperf-netperf-2.7.0/src/missing/m4/sockinttypes.m4  
  inflating: netperf-netperf-2.7.0/src/missing/m4/socklent.m4  
  inflating: netperf-netperf-2.7.0/src/missing/m4/type_socklen_t.m4  
  inflating: netperf-netperf-2.7.0/src/missing/stdint.h  
  inflating: netperf-netperf-2.7.0/src/net_uuid.c  
  inflating: netperf-netperf-2.7.0/src/netcpu.h  
  inflating: netperf-netperf-2.7.0/src/netcpu_kstat.c  
  inflating: netperf-netperf-2.7.0/src/netcpu_kstat10.c  
  inflating: netperf-netperf-2.7.0/src/netcpu_looper.c  
  inflating: netperf-netperf-2.7.0/src/netcpu_none.c  
  inflating: netperf-netperf-2.7.0/src/netcpu_ntperf.c  
  inflating: netperf-netperf-2.7.0/src/netcpu_osx.c  
  inflating: netperf-netperf-2.7.0/src/netcpu_perfstat.c  
  inflating: netperf-netperf-2.7.0/src/netcpu_procstat.c  
  inflating: netperf-netperf-2.7.0/src/netcpu_pstat.c  
  inflating: netperf-netperf-2.7.0/src/netcpu_pstatnew.c  
  inflating: netperf-netperf-2.7.0/src/netcpu_sysctl.c  
  inflating: netperf-netperf-2.7.0/src/netdrv_ethtool.c  
  inflating: netperf-netperf-2.7.0/src/netdrv_none.c  
  inflating: netperf-netperf-2.7.0/src/netdrv_solaris.c  
  inflating: netperf-netperf-2.7.0/src/netfirewall_linux.c  
  inflating: netperf-netperf-2.7.0/src/netfirewall_none.c  
  inflating: netperf-netperf-2.7.0/src/netlib.c  
  inflating: netperf-netperf-2.7.0/src/netlib.h  
  inflating: netperf-netperf-2.7.0/src/netperf.c  
  inflating: netperf-netperf-2.7.0/src/netperf_version.h.in  
  inflating: netperf-netperf-2.7.0/src/netrt_none.c  
  inflating: netperf-netperf-2.7.0/src/netrt_rtmget.c  
  inflating: netperf-netperf-2.7.0/src/netrt_rtnetlink.c  
  inflating: netperf-netperf-2.7.0/src/netsec_linux.c  
  inflating: netperf-netperf-2.7.0/src/netsec_none.c  
  inflating: netperf-netperf-2.7.0/src/netsec_win.c  
  inflating: netperf-netperf-2.7.0/src/netserver.c  
  inflating: netperf-netperf-2.7.0/src/netsh.c  
  inflating: netperf-netperf-2.7.0/src/netsh.h  
  inflating: netperf-netperf-2.7.0/src/netslot_linux.c  
  inflating: netperf-netperf-2.7.0/src/netslot_none.c  
  inflating: netperf-netperf-2.7.0/src/netslot_solaris.c  
  inflating: netperf-netperf-2.7.0/src/netslot_ux1131.c  
  inflating: netperf-netperf-2.7.0/src/netsys_hpux11i.c  
  inflating: netperf-netperf-2.7.0/src/netsys_linux.c  
  inflating: netperf-netperf-2.7.0/src/netsys_none.c  
  inflating: netperf-netperf-2.7.0/src/netsys_solaris.c  
  inflating: netperf-netperf-2.7.0/src/nettest_bsd.c  
  inflating: netperf-netperf-2.7.0/src/nettest_bsd.h  
  inflating: netperf-netperf-2.7.0/src/nettest_dlpi.c  
  inflating: netperf-netperf-2.7.0/src/nettest_dlpi.h  
  inflating: netperf-netperf-2.7.0/src/nettest_omni.c  
  inflating: netperf-netperf-2.7.0/src/nettest_sctp.c  
  inflating: netperf-netperf-2.7.0/src/nettest_sctp.h  
  inflating: netperf-netperf-2.7.0/src/nettest_sdp.c  
  inflating: netperf-netperf-2.7.0/src/nettest_sdp.h  
  inflating: netperf-netperf-2.7.0/src/nettest_unix.c  
  inflating: netperf-netperf-2.7.0/src/nettest_unix.h  
  inflating: netperf-netperf-2.7.0/src/nettest_xti.c  
  inflating: netperf-netperf-2.7.0/src/nettest_xti.h  
[root@localhost tool]# ls
netperf-netperf-2.7.0  netperf.zip
[root@localhost tool]# cd netperf-netperf-2.7.0/
[root@localhost netperf-netperf-2.7.0]# ls
acinclude.m4  ChangeLog     configure     doc          m4           mkinstalldirs    README.aix   README.solaris  src
aclocal.m4    config.guess  configure.ac  inet_ntop.c  Makefile.am  netperf.spec.in  README.hpux  README.vmware
AUTHORS       config.h.in   COPYING       INSTALL      Makefile.in  NEWS             README.osx   README.windows
autogen.sh    config.sub    depcomp       install-sh   missing      README           README.ovms  Release_Notes
[root@localhost netperf-netperf-2.7.0]# ./configure 
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for ranlib... ranlib
checking for an ANSI C-conforming const... yes
checking for main in -lm... yes
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking arpa/inet.h usability... yes
checking arpa/inet.h presence... yes
checking for arpa/inet.h... yes
checking endian.h usability... yes
checking endian.h presence... yes
checking for endian.h... yes
checking errno.h usability... yes
checking errno.h presence... yes
checking for errno.h... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking ifaddrs.h usability... yes
checking ifaddrs.h presence... yes
checking for ifaddrs.h... yes
checking limits.h usability... yes
checking limits.h presence... yes
checking for limits.h... yes
checking linux/tcp.h usability... yes
checking linux/tcp.h presence... yes
checking for linux/tcp.h... yes
checking linux/socket.h usability... yes
checking linux/socket.h presence... yes
checking for linux/socket.h... yes
checking malloc.h usability... yes
checking malloc.h presence... yes
checking for malloc.h... yes
checking netdb.h usability... yes
checking netdb.h presence... yes
checking for netdb.h... yes
checking netinet/in.h usability... yes
checking netinet/in.h presence... yes
checking for netinet/in.h... yes
checking netinet/sctp.h usability... no
checking netinet/sctp.h presence... no
checking for netinet/sctp.h... no
checking sched.h usability... yes
checking sched.h presence... yes
checking for sched.h... yes
checking signal.h usability... yes
checking signal.h presence... yes
checking for signal.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for strings.h... (cached) yes
checking syscall.h usability... yes
checking syscall.h presence... yes
checking for syscall.h... yes
checking sys/ioctl.h usability... yes
checking sys/ioctl.h presence... yes
checking for sys/ioctl.h... yes
checking sys/mman.h usability... yes
checking sys/mman.h presence... yes
checking for sys/mman.h... yes
checking sys/param.h usability... yes
checking sys/param.h presence... yes
checking for sys/param.h... yes
checking sys/socket.h usability... yes
checking sys/socket.h presence... yes
checking for sys/socket.h... yes
checking for sys/stat.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for sys/wait.h... (cached) yes
checking sys/ipc.h usability... yes
checking sys/ipc.h presence... yes
checking for sys/ipc.h... yes
checking sys/sockio.h usability... no
checking sys/sockio.h presence... no
checking for sys/sockio.h... no
checking sys/sysinfo.h usability... yes
checking sys/sysinfo.h presence... yes
checking for sys/sysinfo.h... yes
checking for sys/wait.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking netinet/in_systm.h usability... yes
checking netinet/in_systm.h presence... yes
checking for netinet/in_systm.h... yes
checking netinet/ip.h usability... yes
checking netinet/ip.h presence... yes
checking for netinet/ip.h... yes
checking for main in -lsocket... no
checking for main in -lmach... no
checking for an ANSI C-conforming const... (cached) yes
checking for off_t... yes
checking for size_t... yes
checking for socklen_t equivalent... unsigned
checking for h_errno declaration in netdb.h... yes
checking for struct sockaddr_storage... yes
checking whether time.h and sys/time.h may both be included... yes
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
checking if sockaddr struct has sa_len member... no
checking for pid_t... yes
checking vfork.h usability... no
checking vfork.h presence... no
checking for vfork.h... no
checking for fork... yes
checking for vfork... yes
checking for working fork... yes
checking for working vfork... (cached) yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for sys/param.h... (cached) yes
checking for getpagesize... yes
checking for working mmap... yes
checking sys/select.h usability... yes
checking sys/select.h presence... yes
checking for sys/select.h... yes
checking for sys/socket.h... (cached) yes
checking types of arguments for select... int,fd_set *,struct timeval *
checking whether setpgrp takes no argument... yes
checking return type of signal handlers... void
checking for alarm... yes
checking for bzero... yes
checking for daemon... yes
checking for gethostbyname... yes
checking for gethrtime... no
checking for gettimeofday... yes
checking for inet_ntoa... yes
checking for memset... yes
checking for memcpy... yes
checking for munmap... yes
checking for select... yes
checking for setsid... yes
checking for socket... yes
checking for sqrt... yes
checking for strcasecmp... yes
checking for strchr... yes
checking for strstr... yes
checking for strtoul... yes
checking for uname... yes
checking for toupper... yes
checking for getnameinfo... yes
checking for getaddrinfo... yes
checking for inet_ntop... yes
checking for getifaddrs... yes
checking for sendfile... yes
checking for uname... (cached) yes
checking for mpctl... no
checking for processor_bind... no
checking for sched_setaffinity... yes
checking for bind_to_cpu_id... no
checking for bindprocessor... no
checking whether to include histogram support... no
checking whether to include dirty support... no
checking whether to include demo support... no
checking whether to include Unix-domain socket tests... no
checking whether to include DLPI tests... no
checking whether to include DCCP tests... no
checking whether to include OMNI tests... yes
checking whether to include XTI tests... no
checking whether to include SDP tests... no
checking whether to include ICSC-EXS tests... no
checking whether to include SCTP tests... no
checking whether to include paced send (intervals) support... no
checking whether paced sends should spin... no
checking whether to include initial burst support in _RR tests... yes
checking which CPU utilization measurement type to use... "procstat - auto"
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/netperf_version.h
config.status: creating src/Makefile
config.status: creating src/missing/Makefile
config.status: creating src/missing/m4/Makefile
config.status: creating doc/Makefile
config.status: creating doc/examples/Makefile
config.status: creating netperf.spec
config.status: creating config.h
config.status: executing depfiles commands
[root@localhost netperf-netperf-2.7.0]# make && make install
make  all-recursive
make[1]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0”
Making all in src
make[2]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/src”
Making all in missing
make[3]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing”
Making all in m4
make[4]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing/m4”
make[4]: 对“all”无需做任何事。
make[4]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing/m4”
make[4]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing”
make[4]: 对“all-am”无需做任何事。
make[4]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing”
make[3]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing”
make[3]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/src”
gcc -DHAVE_CONFIG_H -I. -I..      -MT netperf.o -MD -MP -MF .deps/netperf.Tpo -c -o netperf.o netperf.c
mv -f .deps/netperf.Tpo .deps/netperf.Po
gcc -DHAVE_CONFIG_H -I. -I..      -MT netlib.o -MD -MP -MF .deps/netlib.Tpo -c -o netlib.o netlib.c
mv -f .deps/netlib.Tpo .deps/netlib.Po
gcc -DHAVE_CONFIG_H -I. -I..      -MT netsh.o -MD -MP -MF .deps/netsh.Tpo -c -o netsh.o netsh.c
mv -f .deps/netsh.Tpo .deps/netsh.Po
gcc -DHAVE_CONFIG_H -I. -I..      -MT nettest_bsd.o -MD -MP -MF .deps/nettest_bsd.Tpo -c -o nettest_bsd.o nettest_bsd.c
mv -f .deps/nettest_bsd.Tpo .deps/nettest_bsd.Po
gcc -DHAVE_CONFIG_H -I. -I..      -MT nettest_dlpi.o -MD -MP -MF .deps/nettest_dlpi.Tpo -c -o nettest_dlpi.o nettest_dlpi.c
mv -f .deps/nettest_dlpi.Tpo .deps/nettest_dlpi.Po
gcc -DHAVE_CONFIG_H -I. -I..      -MT nettest_unix.o -MD -MP -MF .deps/nettest_unix.Tpo -c -o nettest_unix.o nettest_unix.c
mv -f .deps/nettest_unix.Tpo .deps/nettest_unix.Po
gcc -DHAVE_CONFIG_H -I. -I..      -MT nettest_xti.o -MD -MP -MF .deps/nettest_xti.Tpo -c -o nettest_xti.o nettest_xti.c
mv -f .deps/nettest_xti.Tpo .deps/nettest_xti.Po
gcc -DHAVE_CONFIG_H -I. -I..      -MT nettest_sctp.o -MD -MP -MF .deps/nettest_sctp.Tpo -c -o nettest_sctp.o nettest_sctp.c
mv -f .deps/nettest_sctp.Tpo .deps/nettest_sctp.Po
gcc -DHAVE_CONFIG_H -I. -I..      -MT nettest_sdp.o -MD -MP -MF .deps/nettest_sdp.Tpo -c -o nettest_sdp.o nettest_sdp.c
mv -f .deps/nettest_sdp.Tpo .deps/nettest_sdp.Po
gcc -DHAVE_CONFIG_H -I. -I..      -MT nettest_omni.o -MD -MP -MF .deps/nettest_omni.Tpo -c -o nettest_omni.o nettest_omni.c
mv -f .deps/nettest_omni.Tpo .deps/nettest_omni.Po
gcc -DHAVE_CONFIG_H -I. -I..      -MT net_uuid.o -MD -MP -MF .deps/net_uuid.Tpo -c -o net_uuid.o net_uuid.c
mv -f .deps/net_uuid.Tpo .deps/net_uuid.Po
gcc -DHAVE_CONFIG_H -I. -I..      -MT dscp.o -MD -MP -MF .deps/dscp.Tpo -c -o dscp.o dscp.c
mv -f .deps/dscp.Tpo .deps/dscp.Po
gcc -DHAVE_CONFIG_H -I. -I..      -MT netcpu_procstat.o -MD -MP -MF .deps/netcpu_procstat.Tpo -c -o netcpu_procstat.o netcpu_procstat.c
mv -f .deps/netcpu_procstat.Tpo .deps/netcpu_procstat.Po
gcc     -o netperf netperf.o netlib.o netsh.o nettest_bsd.o nettest_dlpi.o nettest_unix.o nettest_xti.o nettest_sctp.o nettest_sdp.o nettest_omni.o net_uuid.o dscp.o netcpu_procstat.o  -lm 
gcc -DHAVE_CONFIG_H -I. -I..      -MT netserver.o -MD -MP -MF .deps/netserver.Tpo -c -o netserver.o netserver.c
mv -f .deps/netserver.Tpo .deps/netserver.Po
gcc     -o netserver netserver.o netlib.o netsh.o nettest_bsd.o nettest_dlpi.o nettest_unix.o nettest_xti.o nettest_sctp.o nettest_sdp.o nettest_omni.o net_uuid.o dscp.o netcpu_procstat.o  -lm 
make[3]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/src”
make[2]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/src”
Making all in doc
make[2]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/doc”
Making all in examples
make[3]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/doc/examples”
make[3]: 对“all”无需做任何事。
make[3]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/doc/examples”
make[3]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/doc”
make[3]: 对“all-am”无需做任何事。
make[3]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/doc”
make[2]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/doc”
make[2]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0”
make[2]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0”
make[1]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0”
Making install in src
make[1]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/src”
Making install in missing
make[2]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing”
Making install in m4
make[3]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing/m4”
make[4]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing/m4”
make[4]: 对“install-exec-am”无需做任何事。
make[4]: 对“install-data-am”无需做任何事。
make[4]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing/m4”
make[3]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing/m4”
make[3]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing”
make[4]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing”
make[4]: 对“install-exec-am”无需做任何事。
make[4]: 对“install-data-am”无需做任何事。
make[4]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing”
make[3]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing”
make[2]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/src/missing”
make[2]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/src”
make[3]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/src”
test -z "/usr/local/bin" || /usr/bin/mkdir -p "/usr/local/bin"
  /usr/bin/install -c netperf netserver '/usr/local/bin'
make[3]: 对“install-data-am”无需做任何事。
make[3]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/src”
make[2]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/src”
make[1]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/src”
Making install in doc
make[1]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/doc”
Making install in examples
make[2]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/doc/examples”
make[3]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/doc/examples”
make[3]: 对“install-exec-am”无需做任何事。
make[3]: 对“install-data-am”无需做任何事。
make[3]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/doc/examples”
make[2]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/doc/examples”
make[2]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/doc”
make[3]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0/doc”
make[3]: 对“install-exec-am”无需做任何事。
test -z "/usr/local/share/info" || /usr/bin/mkdir -p "/usr/local/share/info"
 /usr/bin/install -c -m 644 ./netperf.info '/usr/local/share/info'
 install-info --info-dir='/usr/local/share/info' '/usr/local/share/info/netperf.info'
install-info: warning: no info dir entry in `/usr/local/share/info/netperf.info'
test -z "/usr/local/share/man/man1" || /usr/bin/mkdir -p "/usr/local/share/man/man1"
 /usr/bin/install -c -m 644 'netperf.man' '/usr/local/share/man/man1/netperf.1'
 /usr/bin/install -c -m 644 'netserver.man' '/usr/local/share/man/man1/netserver.1'
make[3]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/doc”
make[2]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/doc”
make[1]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0/doc”
make[1]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0”
make[2]: 进入目录“/home/songpy/tool/netperf-netperf-2.7.0”
make[2]: 对“install-exec-am”无需做任何事。
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0”
make[1]: 离开目录“/home/songpy/tool/netperf-netperf-2.7.0”
[root@localhost netperf-netperf-2.7.0]# netperf -h

Usage: netperf [global options] -- [test options] 

Global options:
    -a send,recv      Set the local send,recv buffer alignment
    -A send,recv      Set the remote send,recv buffer alignment
    -B brandstr       Specify a string to be emitted with brief output
    -c [cpu_rate]     Report local CPU usage
    -C [cpu_rate]     Report remote CPU usage
    -d                Increase debugging output
    -D time,[units] * Display interim results at least every time interval
                      using units as the initial guess for units per second
                      A negative value for time will make heavy use of the
                      system's timestamping functionality
    -f G|M|K|g|m|k    Set the output units
    -F lfill[,rfill]* Pre-fill buffers with data from specified file
    -h                Display this text
    -H name|ip,fam *  Specify the target machine and/or local ip and family
    -i max,min        Specify the max and min number of iterations (15,1)
    -I lvl[,intvl]    Specify confidence level (95 or 99) (99) 
                      and confidence interval in percentage (10)
    -j                Keep additional timing statistics
    -l testlen        Specify test duration (>0 secs) (<0 bytes|trans)
    -L name|ip,fam *  Specify the local ip|name and address family
    -o send,recv      Set the local send,recv buffer offsets
    -O send,recv      Set the remote send,recv buffer offset
    -n numcpu         Set the number of processors for CPU util
    -N                Establish no control connection, do 'send' side only
    -p port,lport*    Specify netserver port number and/or local port
    -P 0|1            Don't/Do display test headers
    -r                Allow confidence to be hit on result only
    -s seconds        Wait seconds between test setup and test start
    -S                Set SO_KEEPALIVE on the data connection
    -t testname       Specify test to perform
    -T lcpu,rcpu      Request netperf/netserver be bound to local/remote cpu
    -v verbosity      Specify the verbosity level
    -W send,recv      Set the number of send,recv buffers
    -v level          Set the verbosity level (default 1, min 0)
    -V                Display the netperf version and exit
    -y local,remote   Set the socket priority
    -Y local,remote   Set the IP_TOS. Use hexadecimal.
    -Z passphrase     Set and pass to netserver a passphrase

For those options taking two parms, at least one must be specified;
specifying one value without a comma will set both parms to that
value, specifying a value with a leading comma will set just the second
parm, a value with a trailing comma will set just the first. To set
each parm to unique values, specify both and separate them with a
comma.

* For these options taking two parms, specifying one value with no comma
will only set the first parms and will leave the second at the default
value. To set the second value it must be preceded with a comma or be a
comma-separated pair. This is to retain previous netperf behaviour.
[root@localhost netperf-netperf-2.7.0]#

报错:

[root@localhost ~]# netperf -H 192.168.6.212
establish control: are you sure there is a netserver listening on 192.168.6.212 at port 12865?
establish_control could not establish the control connection from 0.0.0.0 port 0 address family AF_UNSPEC to 192.168.6.212 port 12865 address family AF_INET

 

这个错误提示表明 netperf 客户端无法连接到指定的 netserver 服务。确保目标机器上已经启动了 netserver 服务,可以在目标机器上执行以下命令来启动 netserver:

netserver

如果还是无法连接,则要确保目标机器和客户端机器之间的网络连接是正常的。可以尝试通过 ping 命令来测试两台机器之间的网络连接是否正常。例如:

ping 192.168.6.212

如果无法 ping 通,则需要检查网络连接是否正常。

猜你喜欢

转载自blog.csdn.net/songpeiying/article/details/131813575