18 Common commands for monitoring network bandwidth on a Linux server

Source: Internet
Author: User

This article describes some of the Linux command-line tools that you can use to monitor network usage. These tools can monitor data transmitted over a network interface and measure the speed at which data is being transmitted. The inbound traffic is displayed separately from the outbound traffic.

Some commands can show the bandwidth used by a single process. This makes it easy for users to discover a process that is over-using network bandwidth.

These tools use different mechanisms to produce traffic reports. Some tools, such as nload, can read "Proc/net/dev" files for traffic statistics, while some tools use Pcap libraries authoring to capture all packets and then calculate the total amount of data to estimate the traffic load.

Here is the command name by function.

    • Monitor overall bandwidth using ――nload, Bmon, Slurm, Bwm-ng, CBM, speedometer, and netload
    • Monitor overall bandwidth usage (batch output) ――vnstat, Ifstat, Dstat, and Collectl
    • Bandwidth per socket connection using ――iftop, Iptraf, Tcptrack, Pktstat, Netwatch, and Trafshow
    • Bandwidth usage for each process ――nethogs

1. nload

Nload is a command-line tool that allows users to separate and monitor both inbound and outbound traffic. It can also draw charts to show inbound traffic and outbound traffic, and the view scale can be adjusted. It is simple to use and does not support many options.

So, if you just need to quickly see the total bandwidth usage without the details of each process, then nload is handy.

    1. $ nload

Installing Nload:fedora and Ubuntu has nload in the default repositories. CentOS users need to get nload from the Epel Software library.

    1. # Fedora or CentOS
    2. $ yum Install Nload-y
    3. # Ubuntu/debian
    4. $ sudo apt-get install nload

2. Iftop

The Iftop can measure data transmitted through each socket connection, and it works differently from Nload. Iftop uses Pcap libraries authoring to capture packets entering and exiting the network adapter, and then summarizes the packet size and number to figure out the total bandwidth usage.

Although Iftop reports the bandwidth used for each connection, it cannot report the process name/number (ID) that participates in a set of word connections. However, due to the Pcap library, Iftop is able to filter traffic and report bandwidth usage for the selected host connection specified by the filter.

    1. $ sudo iftop-n

The n option prevents Iftop from resolving IP addresses to host names, and parsing itself can bring additional network traffic.

Installing Iftop:ubuntu/debian/fedora users can obtain it from the default software library. CentOS users can get it from Epel.

    1. # Fedora or CentOS
    2. Yum Install Iftop-y
    3. # Ubuntu or Debian
    4. $ sudo apt-get install Iftop

3. Iptraf

The Iptraf is an interactive, brightly colored IP LAN monitoring tool. It can display the amount of data transferred between each connection and the host. Here is the screen.

    1. $ sudo iptraf

Install Iptraf:

    1. # Centos (Basic software Library)
    2. $ yum Install Iptraf
    3. # Fedora or CentOS (with Epel)
    4. $ yum Install Iptraf-ng-y
    5. # Ubuntu or Debian
    6. $ sudo apt-get install Iptraf iptraf-ng

4. Nethogs

The nethogs is a compact "net top" tool that shows the bandwidth used by each process and sorts the list to the top of the process that consumes the most bandwidth. In the event of a sudden surge in bandwidth usage, users can quickly open nethogs and find a process that leads to a surge in bandwidth usage. Nethogs can report the program's process number (PID), user, and path.

    1. $ sudo nethogs

Installing Nethogs:ubuntu, Debian, and fedora users can be obtained from the default repositories. CentOS users are required to Epel.

    1. # Ubuntu or Debian (default software library)
    2. $ sudo apt-get install Nethogs
    3. # Fedora or CentOS (from Epel)
    4. $ sudo yum install nethogs-y

5. Bmon

The Bmon (Bandwidth monitor) is a nload-like tool that can display the traffic load on all network interfaces on the system. The output also contains charts and sections with detailed information at the packet level.

Installing Bmon:ubuntu, Debian, and Fedora users can be installed from the default repositories. CentOS users need to install Repoforge because there is no bmon inside the Epel.

    1. # Ubuntu or Debian
    2. $ sudo apt-get install Bmon
    3. # Fedora or CentOS (from Repoforge)
    4. $ sudo yum install Bmon

Bmon supports many options to produce HTML-formatted reports. For more information, please refer to the Reference manual page.

6. Slurm

The Slurm is another network load monitor that can display the statistics of the device and also display ASCII graphics. It supports three different types of graphics, using the C key, S key, and L keys to activate each type of graphic. The Slurm feature is simple enough to display any further details about the network load.

    1. $ slurm-s-I. eth0

Installing Slurm

    1. # Debian or Ubuntu
    2. $ sudo apt-get install Slurm
    3. # Fedora or CentOS
    4. $ sudo yum install slurm-y

7. Tcptrack

Tcptrack similar to Iftop, captures packets using PCAP libraries Authoring and calculates various statistics, such as the bandwidth used by each connection. It also supports standard PCAP filters, which can be used to monitor specific connections.

Install Tcptrack:ubuntu, Debian, and fedora in the default repositories. The CentOS user needs to get it from Repoforge because there is no epel inside it.

    1. # Ubuntu, Debian
    2. $ sudo apt-get install Tcptrack
    3. # Fedora, CentOS (from Repoforge Software Library)
    4. $ sudo yum install Tcptrack

8. Vnstat

Vnstat is a little different from most other tools. It actually runs the background service/daemon and always keeps track of the size of the transmitted data. , it can be used to create reports that show the history of network usage.

    1. $ Service Vnstat Status
    2. * Vnstat Daemon is running

Running Vnstat with no options will only show the total amount of data transferred since the daemon was run.

  1. $ vnstat
  2. Database Updated:mon Mar 17 15:26:59 2014
  3. Eth0 since 06/12/13
  4. rx:135.14 Gib tx:35.76 Gib total:170.90 GIB
  5. Monthly
  6. Rx |    TX |   Total | Avg. rate
  7. ------------------------+-------------+-------------+-------------
  8. Feb ' 8.19 GiB |   2.08 GiB |   10.27 GiB | 35.60 kbit/s
  9. Mar ' 4.98 GiB |    1.52 GiB |   6.50 GiB | 37.93 kbit/s
  10. ------------------------+-------------+-------------+-------------
  11. Estimated 9.28 GiB |   2.83 GiB | 12.11 GiB |
  12. Daily
  13. Rx |    TX |   Total | Avg. rate
  14. ------------------------+-------------+-------------+-------------
  15. Yesterday 236.11 MiB |  98.61 MiB |   334.72 MiB | 31.74 kbit/s
  16. Today 128.55 MiB |  41.00 MiB |   169.56 MiB | 24.97 kbit/s
  17. ------------------------+-------------+-------------+-------------
  18. Estimated 199 MiB |     MiB | 262 MiB |

To monitor bandwidth usage in real time, use the "-l" option (Live mode). It then displays the total amount of bandwidth used by inbound and outbound data, but is displayed very accurately without any internal details about the host connection or process.

    1. $ vnstat-l-I. eth0
    2. Monitoring eth0 ... (press Ctrl-c to stop)
    3. Rx:12 kbit/s p/s tx:12 kbit/s one p/s

Vnstat is more like a tool for making historical reports that shows how much bandwidth is used per day or in the past one months. It is not strictly a tool for real-time monitoring of the network.

Vnstat supports a number of options, and more information about which options to support, see the Reference man page.

Installing Vnstat

    1. # Ubuntu or Debian
    2. $ sudo apt-get install Vnstat
    3. # Fedora or CentOS (from Epel)
    4. $ sudo yum install Vnstat

9. Bwm-ng

The Bwm-ng (Next generation bandwidth monitor) is another very simple real-time Network load Monitoring tool that reports summary information and shows the transfer speed of different data to and from all available network interfaces on the system.

  1. $ bwm-ng
  2. Bwm-ng v0.6 (probing every 0.500s), press ' H ' for help
  3. Input:/proc/net/dev type:rate
  4. /iface Rx Tx T
  5. ot=================================================================
  6. = = eth0:0.53 kb/s 1.31 kb/s 1.84
  7. KB lo:0.00 kb/s 0.00 kb/s 0.00
  8. KB-------------------------------------------------------------------------------------------------------------
  9. total:0.53 kb/s 1.31 kb/s 1.84
  10. kb/s

If the console is large enough, bwm-ng can also use the Curses2 output mode to draw a bar chart for traffic.

    1. $ bwm-ng-o Curses2

Install Bwm-ng: On CentOS, you can install Bwm-ng from Epel.

    1. # Ubuntu or Debian
    2. $ sudo apt-get install Bwm-ng
    3. # Fedora or CentOS (from Epel)
    4. $ sudo apt-get install Bwm-ng

Cbm:color Bandwidth Meter

This is a small and simple bandwidth monitoring tool that can display the traffic size through the network interface. There is no further option to display and update the statistics of traffic only in real time.

    1. $ sudo apt-get install CBM

Speedometer.

This is another small and simple tool that only draws beautiful graphics that show inbound traffic and outbound traffic over an interface.

    1. $ speedometer-r eth0-t eth0

Installing speedometer

    1. # Ubuntu or Debian users
    2. $ sudo apt-get install speedometer

Pktstat.

Pktstat can display all active connections in real time and show what data is transmitted through these active connections. It can also display the connection type, such as a TCP connection or a UDP connection, and, if an HTTP connection is involved, also displays details about the HTTP request.

    1. $ sudo pktstat-i eth0-nt
    2. $ sudo apt-get install Pktstat

Netwatch.

Netwatch is part of the Netdiag tool library, which also shows the connection between the local host and other remote hosts and shows what data is being transmitted on each connection.

    1. $ sudo netwatch-e eth0-nt
    2. $ sudo apt-get install netdiag

Trafshow.

Like Netwatch and Pktstat, Trafshow can also report current active connections, the protocols they use, and the speed of data transfer on each connection. It can use the Pcap type filter to filter the connection.

Monitoring only TCP connections

    1. $ sudo trafshow-i eth0 TCP
    2. $ sudo apt-get install netdiag

Netload.

The netload command displays only a short report about the current traffic load and shows the total bytes transferred since the program started. There are no more feature features. It is part of the Netdiag.

    1. $ netload eth0
    2. $ sudo apt-get install netdiag

Ifstat.

Ifstat can display network bandwidth in batch mode. The output uses a format that allows users to log and analyze using other programs or utilities.

    1. $ ifstat-t-I eth0 0.5
    2. Time eth0
    3. HH:MM:SS kb/s in kb/s out
    4. 09:59:21 2.62 2.80
    5. 09:59:22 2.10 1.78
    6. 09:59:22 2.67 1.84
    7. 09:59:23 2.06 1.98
    8. 09:59:23 1.73 1.79

Installing Ifstat:ubuntu, Debian, and Fedora users has it in the default repositories. The CentOS user needs to get it from Repoforge because there is no epel inside it.

    1. # Ubuntu, Debian
    2. $ sudo apt-get install Ifstat
    3. # Fedora, CentOS (Repoforge)
    4. $ sudo yum install Ifstat

Dstat.

Dstat is a versatile tool (written in Python) that monitors different statistical information for a system, reports using batch mode, or writes related data to a CSV or similar file. This example shows how to use Dstat to report network bandwidth.

Installing Dstat

    1. $ dstat-nt
    2. -net/total-----System----
    3. Recv send| Time
    4. 0 0 |23-03 10:27:13
    5. 1738B 1810b|23-03 10:27:14
    6. 2937B 2610b|23-03 10:27:15
    7. 2319B 2232b|23-03 10:27:16
    8. 2738B 2508b|23-03 10:27:17

Collectl.

COLLECTL reports the statistics of the system in a similar dstat format; like Dstat, it collects statistical information about different resources of the system, such as processors, memory, and networks. A simple example given here shows how to use COLLECTL to report network usage/bandwidth.

  1. $ collectl-sn-ot-i0.5
  2. Waiting for 0.5 second sample ...
  3. # <----------Network---------->
  4. #Time kbin pktin kbout pktout
  5. 10:32:01 40 58 43 66
  6. 10:32:01 27 58 3 32
  7. 10:32:02 3 28 9 44
  8. 10:32:02 5 42 96 96
  9. 10:32:03 5 48 3 28

Installing Collectl

    1. # Ubuntu/debian Users
    2. $ sudo apt-get install Collectl
    3. #Fedora
    4. $ sudo yum install Collectl

Conclusion

These easy-to-use commands can quickly check network bandwidth usage on Linux servers. However, these commands require the user to log on to the remote server via SSH. In addition, web-based monitoring tools can also be used to accomplish the same task.

Ntop and Darkstat are among the two basic web-based network monitoring tools for Linux systems. In addition to enterprise-class monitoring tools such as Nagios, they provide a number of features that not only monitor the server, but also monitor the entire infrastructure.

18 Common commands for monitoring network bandwidth on a Linux server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.