[Reprint] a big wave you may not know the Linux networking tools

A big wave you may not know the Linux networking tools

https://linux.cn/article-5435-1.html

 

Author:  Bobbin Zachariah  Translator:  LCTT  FSSlc 

| 2015-05-12 14:52 Comments:  4  Favorites:  24    

If you want to monitor the network on your system, then use the command-line tool is very useful, and for Linux users, with many ready-made tools available, such as: nethogs, ntopng, nload, iftop, iptraf, bmon , slurm, tcptrack, cbm, netwatch, collectl, trafshow, cacti, etherape, ipband, jnettop, netspeed and speedometer.

In view of the Linux world there are many experts and developers, obviously there are other network monitoring tools, but in this tutorial, I'm not going to include them all.

Tools listed above has its own unique features, but ultimately, they are doing the work of monitoring network traffic, but through a variety of different ways. For example nethogs can be used to display the bandwidth usage of each process, in case you want to know exactly which applications consume your whole network resources; iftop can be used to display the bandwidth usage of each socket connection, and like nload of these tools can help you get information about the entire bandwidth.

1) nethogs

nethogs is a free tool when you want to find out which PID (Note: the process identifier, process ID) of network traffic when you brought trouble, it is very convenient. It grouped the bandwidth for each process, rather than as most of the tools for each protocol or to divide the traffic for each subnet. It is feature-rich, supports both IPv4 and IPv6, and I think, if you want to determine which programs are consuming your bandwidth all on your Linux host, it is best to do this procedure.

A user can use Linux to display TCP nethogs download and upload rate for each process, you can use the command nethogs eth0 to monitor a specific device, the above eth0 is the name of the device that you want to get information, you can also get are related transmission rate information data transmitted.

For me, nethogs is very easy to use, perhaps because I like it very much, so I always use it on my Ubuntu 12.04 LTS machine to monitor my network bandwidth.

For example in order to use promiscuous mode to sniff, so you can use the command options as presented below -p:

  1. nethogs -p wlan0

If you want to know more about nethogs and explore it in depth, so please do not hesitate to read the whole tutorial on that network bandwidth monitoring tools we do.

(LCTT Annotation: For more information about the nethogs can refer to: https://linux.cn/article-2808-1.html  )

2) nload

nload is a console application that can be used to monitor network traffic and real-time bandwidth usage, it to be visualized by providing two flow charts straightforward. The perfect network monitoring tool may further switching device being monitored in the monitoring process, which can be done by pressing the left or right arrow.

network monitoring tools in linux

network monitoring tools in linux

As you can see in the screenshot above it, a chart provided by the nload is very easy to understand. nload provide useful information, and also shows the total minimum / maximum network rate and other information such as data to be transmitted.

The cooler is that you only need to run this tool nload on the line, this command is very short and easy to remember:

  1. nload

I'm pretty sure: we detailed tutorial on how to use nload will help to new Linux users, and even can help those who are looking for information about nload veteran.

(LCTT Annotation: updated information about nload can refer to: https://linux.cn/article-5114-1.html  )

3) slurm

slurm Linux network load monitor is another tool, which displays the results in a good FIG ASCII, it also supports a number of buttons for interaction, for example for switching to the classic mode c, s switched to the sub mode, FIG, for R & lt weight screen painting, L to enable TX / RX lamp (Note: TX, sending traffic; RX, receive traffic), m for division between the classical and enlarge view schematically mode switching, q exit slurm.

linux network load monitoring tools

linux network load monitoring tools

In the network load monitoring tools slurm, there are many other buttons available, you can easily use the following commands to learn them in man manual.

  1. man slurm

slurm can be found in the official repositories of Ubuntu and Debian, so users can use these distributions as shown below, using the apt-get command to install easily download it:

  1. sudo apt-get install slurm

We have a tutorial in using slurm made the introduction, do not forget to use Linux and other friends to share this knowledge.

4) iftop

When you want to connect to the display bandwidth usage of each host on the network card, iftop is a very useful tool. According to the man page, iftop in a specified interface or the first interface it can find (if no special circumstances, it should be an external interface) monitor network traffic on a table to display and demonstrate a current bandwidth usage between hosts.

By using the following command in the virtual terminal, Ubuntu and Debian users can easily install on their machines iftop:

  1. sudo apt-get install iftop

在你的机器上,可以使用下面的命令通过 yum 来安装 iftop:

  1. yum -y install iftop

(LCTT 译注:关于 nload 的更多信息请参考:https://linux.cn/article-1843-1.html )

5) collectl

collectl 可以被用来收集描述当前系统状态的数据,并且它支持如下两种模式:

  • 记录模式
  • 回放模式

记录模式 允许从一个正在运行的系统中读取数据,然后将这些数据要么显示在终端中,要么写入一个或多个文件或一个套接字中。

回放模式

根据 man 手册,在这种模式下,数据从一个或多个由记录模式生成的数据文件中读取。

Ubuntu 和 Debian 用户可以在他们的机器上使用他们默认的包管理器来安装 colletcl。下面的命令将为他们做这个工作:

  1. sudo apt-get install collectl

还可以使用下面的命令来安装 collectl, 因为对于这些发行版本(注:这里指的是用 yum 作为包管理器的发行版本),在它们官方的软件仓库中也含有 collectl:

  1. yum install collectl

(LCTT 译注:关于 collectl 的更多信息请参考: https://linux.cn/article-3154-1.html )

6) Netstat

Netstat 是一个用来监控传入和传出的网络数据包统计数据的接口统计数据命令行工具。它会显示 TCP 连接 (包括上传和下行),路由表,及一系列的网络接口(网卡或者SDN接口)和网络协议统计数据。

Ubuntu 和 Debian 用户可以在他们的机器上使用默认的包管理器来安装 netstat。Netsta 软件被包括在 net-tools 软件包中,并可以在 shell 或虚拟终端中运行下面的命令来安装它:

  1. sudo apt-get install net-tools

CentOS, Fedora, RHEL 用户可以在他们的机器上使用默认的包管理器来安装 netstat。Netstat 软件被包括在 net-tools 软件包中,并可以在 shell 或虚拟终端中运行下面的命令来安装它:

  1. yum install net-tools

运行下面的命令使用 Netstat 来轻松地监控网络数据包统计数据:

  1. netstat

Netstat

Netstat

更多的关于 netstat 的信息,我们可以简单地在 shell 或终端中键入 man netstat 来了解:

  1. man netstat

man netstat

man netstat

(LCTT 译注:关于 netstat 的更多信息请参考:https://linux.cn/article-2434-1.html )

7) Netload

netload 命令只展示一个关于当前网络荷载和自从程序运行之后传输数据总的字节数目的简要报告,它没有更多的功能。它是 netdiag 软件的一部分。

我们可以在 fedora 中使用 yum 来安装 Netload,因为它在 fedora 的默认软件仓库中。但假如你运行的是 CentOS 或 RHEL,则我们需要安装 rpmforge 软件仓库

  1. # yum install netdiag

Netload 是默认仓库中 netdiag 的一部分,我们可以轻易地使用下面的命令来利用 apt 包管理器安装 netdiag:

  1. $ sudo apt-get install netdiag

为了运行 netload,我们需要确保选择了一个正在工作的网络接口的名称,如 eth0, eh1, wlan0, mon0等,然后在 shell 或虚拟终端中运行下面的命令:

  1. $ netload wlan2

注意: 请将上面的 wlan2 替换为你想使用的网络接口名称,假如你想通过扫描了解你的网络接口名称,可以在一个虚拟终端或 shell 中运行 ip link show 命令。

8) Nagios

Nagios 是一个领先且功能强大的开源监控系统,它使得网络或系统管理员可以在服务器的各种问题影响到服务器的主要事务之前,发现并解决这些问题。 有了 Nagios 系统,管理员便可以在一个单一的窗口中监控远程的 Linux 、Windows 系统、交换机、路由器和打印机等。它会显示出重要的警告并指出在你的网络或服务器中是否出现某些故障,这可以间接地帮助你在问题发生前就着手执行补救行动。

Nagios 有一个 web 界面,其中有一个图形化的活动监视器。通过浏览网页 http://localhost/nagios/ 或 http://localhost/nagios3/ 便可以登录到这个 web 界面。假如你在远程的机器上进行操作,请使用你的 IP 地址来替换 localhost,然后键入用户名和密码,我们便会看到如下图所展示的信息:

Nagios3 in the Chromium browser

在 Chromium 浏览器中的 Nagios3

(LCTT 译注:关于 Nagios 的更多信息请参考:https://linux.cn/article-2436-1.html )

9) EtherApe

EtherApe 是一个针对 Unix 的图形化网络监控工具,它仿照了 etherman 软件。它支持链路层、IP 和 TCP 等模式,并支持以太网, FDDI, 令牌环, ISDN, PPP, SLIP 及 WLAN 设备等接口,以及一些封装格式。主机和连接随着流量和协议而改变其尺寸和颜色。它可以过滤要展示的流量,并可从一个文件或运行的网络中读取数据包。

在 CentOS、Fedora、RHEL 等 Linux 发行版本中安装 etherape 是一件容易的事,因为在它们的官方软件仓库中就可以找到 etherape。我们可以像下面展示的命令那样使用 yum 包管理器来安装它:

  1. yum install etherape

我们也可以使用下面的命令在 Ubuntu、Debian 及它们的衍生发行版本中使用 apt 包管理器来安装 EtherApe :

  1. sudo apt-get install etherape

在 EtherApe 安装到你的系统之后,我们需要像下面那样以 root 权限来运行 etherape:

  1. sudo etherape

然后, etherape 的 图形用户界面 便会被执行。接着,在菜单上面的 捕捉 选项下,我们可以选择 模式(IP,链路层,TCP) 和 接口。一切设定完毕后,我们需要点击 开始 按钮。接着我们便会看到类似下面截图的东西:

EtherApe

EtherApe

10) tcpflow

tcpflow 是一个命令行工具,它可以捕捉 TCP 连接(流)的部分传输数据,并以一种方便协议分析或除错的方式来存储数据。它重构了实际的数据流并将每个流存储在不同的文件中,以备日后的分析。它能识别 TCP 序列号并可以正确地重构数据流,不管是在重发还是乱序发送状态下。

通过 apt 包管理器在 Ubuntu 、Debian 系统中安装 tcpflow 是很容易的,因为默认情况下在官方软件仓库中可以找到它。

  1. $ sudo apt-get install tcpflow

我们可以使用下面的命令通过 yum 包管理器在 Fedora 、CentOS 、RHEL 及它们的衍生发行版本中安装 tcpflow:

  1. # yum install tcpflow

假如在软件仓库中没有找到它或不能通过 yum 包管理器来安装它,则我们需要像下面展示的那样从 http://pkgs.repoforge.org/tcpflow/ 上手动安装它:

假如你运行 64 位的 PC:

  1. # yum install --nogpgcheck http://pkgs.repoforge.org/tcpflow/tcpflow-0.21-1.2.el6.rf.x86_64.rpm

假如你运行 32 位的 PC:

  1. # yum install --nogpgcheck http://pkgs.repoforge.org/tcpflow/tcpflow-0.21-1.2.el6.rf.i686.rpm

我们可以使用 tcpflow 来捕捉全部或部分 tcp 流量,并以一种简单的方式把它们写到一个可读的文件中。下面的命令就可以完成这个事情,但我们需要在一个空目录中运行下面的命令,因为它将创建诸如 x.x.x.x.y-a.a.a.a.z 格式的文件,运行之后,只需按 Ctrl-C 便可停止这个命令。

  1. $ sudo tcpflow -i eth0 port 8000

注意:请将上面的 eth0 替换为你想捕捉的网卡接口名称。

11) IPTraf

IPTraf 是一个针对 Linux 平台的基于控制台的网络统计应用。它生成一系列的图形,如 TCP 连接的包/字节计数、接口信息和活动指示器、 TCP/UDP 流量故障以及局域网内设备的包/字节计数。

在默认的软件仓库中可以找到 IPTraf,所以我们可以使用下面的命令通过 apt 包管理器轻松地安装 IPTraf:

  1. $ sudo apt-get install iptraf

我们可以使用下面的命令通过 yum 包管理器轻松地安装 IPTraf:

  1. # yum install iptraf

我们需要以管理员权限来运行 IPTraf,并带有一个有效的网络接口名。这里,我们的网络接口名为 wlan2,所以我们使用 wlan2 来作为参数:

  1. $ sudo iptraf wlan2

IPTraf

IPTraf

开始通常的网络接口统计,键入:

  1. # iptraf -g

查看接口 eth0 的详细统计信息,使用:

  1. # iptraf -d eth0

查看接口 eth0 的 TCP 和 UDP 监控信息,使用:

  1. # iptraf -z eth0

查看接口 eth0 的包的大小和数目,使用:

  1. # iptraf -z eth0

注意:请将上面的 eth0 替换为你的接口名称。你可以通过运行ip link show命令来检查你的接口。

(LCTT 译注:关于 iptraf 的更多详细信息请参考:https://linux.cn/article-5430-1.html )

12) Speedometer

Speedometer 是一个小巧且简单的工具,它只用来绘出一幅包含有通过某个给定端口的上行、下行流量的好看的图。

在默认的软件仓库中可以找到 Speedometer ,所以我们可以使用下面的命令通过 yum 包管理器轻松地安装 Speedometer:

  1. # yum install speedometer

我们可以使用下面的命令通过 apt 包管理器轻松地安装 Speedometer:

  1. $ sudo apt-get install speedometer

Speedometer 可以简单地通过在 shell 或虚拟终端中执行下面的命令来运行:

  1. $ speedometer -r wlan2 -t wlan2

Speedometer

Speedometer

注:请将上面的 wlan2 替换为你想要使用的网络接口名称。

13) Netwatch

Netwatch 是 netdiag 工具集里的一部分,它也显示当前主机和其他远程主机的连接情况,以及在每个连接中数据传输的速率。

我们可以使用 yum 在 fedora 中安装 Netwatch,因为它在 fedora 的默认软件仓库中。但若你运行着 CentOS 或 RHEL , 我们需要安装 rpmforge 软件仓库

  1. # yum install netwatch

Netwatch 是 netdiag 的一部分,可以在默认的软件仓库中找到,所以我们可以轻松地使用下面的命令来利用 apt 包管理器安装 netdiag:

  1. $ sudo apt-get install netdiag

为了运行 netwatch, 我们需要在虚拟终端或 shell 中执行下面的命令:

  1. $ sudo netwatch -e wlan2 -nt

Netwatch

Netwatch

注意: 请将上面的 wlan2 替换为你想使用的网络接口名称,假如你想通过扫描了解你的网络接口名称,可以在一个虚拟终端或 shell 中运行 ip link show 命令。

14) Trafshow

Trafshow 同 netwatch 和 pktstat 一样,可以报告当前活动的连接里使用的协议和每个连接中数据传输的速率。它可以使用 pcap 类型的过滤器来筛选出特定的连接。

我们可以使用 yum 在 fedora 中安装 trafshow ,因为它在 fedora 的默认软件仓库中。但若你正运行着 CentOS 或 RHEL , 我们需要安装 rpmforge 软件仓库

  1. # yum install trafshow

Trafshow 在默认仓库中可以找到,所以我们可以轻松地使用下面的命令来利用 apt 包管理器安装它:

  1. $ sudo apt-get install trafshow

为了使用 trafshow 来执行监控任务,我们需要在虚拟终端或 shell 中执行下面的命令:

  1. $ sudo trafshow -i wlan2

Trafshow

Trafshow

为了专门监控 tcp 连接,如下面一样添加上 tcp 参数:

  1. $ sudo trafshow -i wlan2 tcp

Trafshow tcp

Trafshow tcp

注意: 请将上面的 wlan2 替换为你想使用的网络接口名称,假如你想通过扫描了解你的网络接口名称,可以在一个虚拟终端或 shell 中运行 ip link show 命令。

15) Vnstat

与大多数的其他工具相比,Vnstat 有一点不同。实际上它运行着一个后台服务或守护进程,并时刻记录着传输数据的大小。另外,它可以被用来生成一个网络使用历史记录的报告。

我们需要开启 EPEL 软件仓库,然后运行 yum 包管理器来安装 vnstat。

  1. # yum install vnstat

Vnstat 在默认软件仓库中可以找到,所以我们可以使用下面的命令运行 apt 包管理器来安装它:

  1. $ sudo apt-get install vnstat

不带有任何选项运行 vnstat 将简单地展示出从该守护进程运行后数据传输的总量。

  1. $ vnstat

vnstat

vnstat

为了实时地监控带宽使用情况,使用 ‘-l’ 选项(live 模式)。然后它将以一种非常精确的方式来展示上行和下行数据所使用的带宽总量,但不会显示任何有关主机连接或进程的内部细节。

  1. $ vnstat -l

Vnstat real-time mode

Vnstat 实时模式

完成了上面的步骤后,按 Ctrl-C 来停止,这将会得到如下类型的输出:

Vnstat real-time results

Vnstat 实时结果

16) tcptrack

tcptrack 可以展示 TCP 连接的状态,它在一个给定的网络端口上进行监听。tcptrack 监控它们的状态并展示出排序且不断更新的列表,包括来源/目标地址、带宽使用情况等信息,这与 top 命令的输出非常类似 。

鉴于 tcptrack 在软件仓库中,我们可以轻松地在 Debian、Ubuntu 系统中从软件仓库使用 apt 包管理器来安装 tcptrack。为此,我们需要在 shell 或虚拟终端中执行下面的命令:

  1. $ sudo apt-get install tcptrack

我们可以通过 yum 在 fedora 中安装它,因为它在 fedora 的默认软件仓库中。但若你运行着 CentOS 或 RHEL 系统,我们需要安装 rpmforge 软件仓库。为此,我们需要运行下面的命令:

  1. # wget http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
  2. # rpm -Uvh rpmforge-release*rpm
  3. # yum install tcptrack

注:这里我们下载了 rpmforge-release 的当前最新版本,即 0.5.3-1,你总是可以从 rpmforge 软件仓库中下载其最新版本,并请在上面的命令中替换为你下载的版本。

tcptrack 需要以 root 权限或超级用户身份来运行。执行 tcptrack 时,我们需要带上要监视的网络接口 TCP 连接状况的接口名称。这里我们的接口名称为 wlan2,所以如下面这样使用:

  1. sudo tcptrack -i wlan2

tcptrack

tcptrack

假如你想监控特定的端口,则使用:

  1. # tcptrack -i wlan2 port 80

tcptrack port 80

tcptrack port 80

请替换上面的 80 为你想要监控的端口号。注意: 请将上面的 wlan2 替换为你想使用的网络接口名称,假如你想通过扫描了解你的网络接口名称,可以在一个虚拟终端或 shell 中运行 ip link show 命令。

17) CBM

CBM ( Color Bandwidth Meter) 可以展示出当前所有网络设备的流量使用情况。这个程序是如此的简单,以至于都可以从它的名称中看出其功能。CBM 的源代码和新版本可以在 http://www.isotton.com/utils/cbm/ 上找到。

鉴于 CBM 已经包含在软件仓库中,我们可以简单地使用 apt 包管理器从 Debian、Ubuntu 的软件仓库中安装 CBM。为此,我们需要在一个 shell 窗口或虚拟终端中运行下面的命令:

  1. $ sudo apt-get install cbm

我们只需使用下面展示的命令来在 shell 窗口或虚拟终端中运行 cbm:

  1. $ cbm

Color Bandwidth Meter

Color Bandwidth Meter

18) bmon

Bmon ( Bandwidth Monitoring) ,是一个用于调试和实时监控带宽的工具。这个工具能够检索各种输入模块的统计数据。它提供了多种输出方式,包括一个基于 curses 库的界面,轻量级的HTML输出,以及 ASCII 输出格式。

bmon 可以在软件仓库中找到,所以我们可以通过使用 apt 包管理器来在 Debian、Ubuntu 中安装它。为此,我们需要在一个 shell 窗口或虚拟终端中运行下面的命令:

  1. $ sudo apt-get install bmon

我们可以使用下面的命令来运行 bmon 以监视我们的网络状态:

  1. $ bmon

bmon

bmon

19) tcpdump

TCPDump 是一个用于网络监控和数据获取的工具。它可以为我们节省很多的时间,并可用来调试网络或服务器的相关问题。它可以打印出在某个网络接口上与布尔表达式相匹配的数据包所包含的内容的一个描述。

tcpdump 可以在 Debian、Ubuntu 的默认软件仓库中找到,我们可以简单地以 sudo 权限使用 apt 包管理器来安装它。为此,我们需要在一个 shell 窗口或虚拟终端中运行下面的命令:

  1. $ sudo apt -get install tcpdump

tcpdump 也可以在 Fedora、CentOS、RHEL 的软件仓库中找到。我们可以像下面一样通过 yum 包管理器来安装它:

  1. # yum install tcpdump

tcpdump 需要以 root 权限或超级用户来运行,我们需要带上我们想要监控的 TCP 连接的网络接口名称来执行 tcpdump 。在这里,我们有 wlan2 这个网络接口,所以可以像下面这样使用:

  1. $ sudo tcpdump -i wlan2

tcpdump

tcpdump

假如你只想监视一个特定的端口,则可以运行下面的命令。下面是一个针对 80 端口(网络服务器)的例子:

  1. $ sudo tcpdump -i wlan2 'port 80'

tcpdump port

tcpdump port

20) ntopng

ntopng 是 ntop 的下一代版本。它是一个用于展示网络使用情况的网络探头,在一定程度上它与 top 针对进程所做的工作类似。ntopng 基于 libpcap 并且它以可移植的方式被重写,以达到可以在每一个 Unix 平台 、 MacOSX 以及 Win32 上运行的目的。

为了在 Debian,Ubuntu 系统上安装 ntopng,首先我们需要安装 编译 ntopng 所需的依赖软件包。你可以通过在一个 shell 窗口或一个虚拟终端中运行下面的命令来安装它们:

  1. $ sudo apt-get install libpcap-dev libglib2.0-dev libgeoip-dev redis-server wget libxml2-dev build-essential checkinstall

现在,我们需要像下面一样针对我们的系统手动编译 ntopng :

  1. $ sudo wget http://sourceforge.net/projects/ntop/files/ntopng/ntopng-1.1_6932.tgz/download
  2. $ sudo tar zxfv ntopng-1.1_6932.tgz
  3. $ sudo cd ntopng-1.1_6932
  4. $ sudo ./configure
  5. $ sudo make
  6. $ sudo make install

这样,在你的 Debian 或 Ubuntu 系统上应该已经安装上了你编译的 ntopng 。

We already have about the use of ntopng of course , It can also be used in the Web interface on the command line, we can go to these tutorials to gain knowledge about the ntopng.

in conclusion

In this article, we introduce some of the network load monitoring tools in Linux, which for even novice system administrators are very helpful. In this article we describe each tool has its own characteristics, different options and so on, but in the end they can help you to monitor your network traffic.


via: http://linoxide.com/monitoring-2/network-monitoring-tools-linux/

Author: Bobbin Zachariah  Translator: FSSlc  proofread: wxy

This article from the  LCTT  original translation, Linux China  is proud

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/12084821.html