18 Common commands for monitoring network bandwidth on Linux servers

Source: Internet
Author: User

Bkjia: This article describes some Linux Command Line tools that can be used to monitor network usage. These tools can monitor data transmitted through network interfaces and measure the current data transmission speed. The inbound traffic and outbound traffic are displayed separately.

Some commands can display the bandwidth used by a single process. In this way, you can easily find a process that overuses network bandwidth.

These tools use different mechanisms to create traffic reports. Nload and other tools can read the "proc/net/dev" file to obtain traffic statistics. Some tools use the pcap library to capture all data packets and then calculate the total data volume, to estimate the traffic load.

The following is the command name by function.

  • Monitor overall bandwidth usage-nload, bmon, slurm, bwm-ng, cbm, speedometer, and netload
  • Monitor the overall bandwidth usage in batches)-vnstat, ifstat, dstat, and collectl
  • Bandwidth usage for each socket connection-iftop, iptraf, tcptrack, pktstat, netwatch, and trafshow
  • Bandwidth usage of each process-nethogs

1. nload

Nload is a command line tool that allows users to separately monitor inbound and outbound traffic. It can also draw charts to show inbound traffic and outbound traffic. The view ratio can be adjusted. It is easy to use and does not support many options.

Therefore, if you only need to quickly view the total bandwidth usage without the details of each process, it is very convenient to use nload.

 
 
  1. $ nload 

Install nload: Both Fedora and Ubuntu have nload in the default software library. CentOS users need to obtain 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

Iftop can measure the data transmitted through each socket connection. It works differently from nload. Iftop uses the pcap library to capture data packets entering and exiting the network adapter, and then summarizes the data packet size and quantity to figure out the total bandwidth usage.

Although iftop reports the bandwidth used by each connection, it cannot report the name/ID of the process involved in a set of connected words ). However, based on the pcap library, iftop can filter traffic and report the bandwidth usage of the selected host connection specified by the filter.

 
 
  1. $ sudo iftop -n 

The n option prevents iftop from resolving an IP address to a host name, which in turn results in additional network traffic.

Install iftop: Ubuntu/Debian/Fedora users can obtain it from the default software library. CentOS users can obtain it from Epel.

 
 
  1. # Fedora or centos
  2. Yum install iftop-y
  3. # Ubuntu or debian
  4. $ Sudo apt-get install iftop

3. iptraf

Iptraf is an interactive and colorful ip lan monitoring tool. It displays the data volume transmitted between each connection and the host. Below 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-ng

4. nethogs

Nethogs is a small "net top" tool that displays the bandwidth used by each process and sorts the list to top the list of processes that consume the most bandwidth. In case of a sudden surge in bandwidth usage, users can quickly open nethogs to find the process that leads to a surge in bandwidth usage. Nethogs can report the program's process id pid), user, and path.

 
 
  1. $ sudo nethogs 

Install nethogs: Ubuntu, Debian, and Fedora can be obtained from the default software library. For CentOS users, Epel is required.

 
 
  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

Bmon bandwidth monitor) is a tool similar to nload, which can display the traffic load of all network interfaces on the system. The output results also contain charts and sections with detailed information on the data packet layer.

Install bmon: Ubuntu, Debian, and Fedora can be installed from the default software library. CentOS users need to install repoforge because there is no bmon in 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 create reports in HTML format. For more information, see the reference manual page.

6. slurm

Slurm is another network load monitor that displays device statistics and ASCII images. It supports three different types of graphics. You can activate each type of graphics by using the c key, s key, and l key. Slurm is simple and cannot display any further details about the network load.

 
 
  1. $ slurm -s -i eth0 

Install slurm

 
 
  1. # Debian or ubuntu
  2. $ Sudo apt-get install slurm
  3. # Fedora or centos
  4. $ Sudo yum install slurm-y

7. tcptrack

Similar to iftop, tcptrack uses the pcap library to capture data packets and calculate various statistical information, such as the bandwidth used by each connection. It also supports standard pcap filters that can be used to monitor specific connections.

Install tcptrack: Ubuntu, Debian, and Fedora are available in the default software library. CentOS users need to obtain it from RepoForge because it is not in Epel.

 
 
  1. # Ubuntu and 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 process and keeps recording the size of transmitted data. In addition, it can be used to create reports showing the network usage history.

 
 
  1. $ service vnstat status 
  2. * vnStat daemon is running 

Running vnstat without any options only displays the total amount of data transmitted since the daemon is running.

 
 
  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. ------------------------+-------------+-------------+------------- 
  9. Feb '14      8.19 GiB  |    2.08 GiB  |   10.27 GiB |   35.60 kbit/s 
  10. Mar '14      4.98 GiB  |    1.52 GiB  |    6.50 GiB |   37.93 kbit/s 
  11. ------------------------+-------------+-------------+------------- 
  12. estimated       9.28 GiB |    2.83 GiB  |   12.11 GiB | 
  13. daily 
  14. rx      |     tx      |    total    |   avg. rate 
  15. ------------------------+-------------+-------------+------------- 
  16. yesterday     236.11 MiB |   98.61 MiB |  334.72 MiB |   31.74 kbit/s 
  17. today    128.55 MiB |   41.00 MiB |  169.56 MiB |   24.97 kbit/s 
  18. ------------------------+-------------+-------------+------------- 
  19. estimated       199 MiB |      63 MiB |     262 MiB | 

To monitor bandwidth usage in real time, use the "-l" option in real-time mode ). It then displays the total bandwidth used by the inbound and outbound data, but very precisely shows that there is no 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    10 p/s          tx:       12 kbit/s    11 p/s 

Vnstat is more like a tool for making historical reports, showing how much bandwidth is used every day or the past month. It is not a strictly real-time network monitoring tool.

Vnstat supports many options. For more information about the options supported, see the reference manual.

Install 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

Bwm-ng (Next Generation bandwidth monitor) is another simple real-time network load monitoring tool that can report summary information to show the transmission speed of different data 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 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

10. cbm: Color Bandwidth Meter

This is a small and simple bandwidth monitoring tool that shows the traffic volume through various network interfaces. No further options are available. Only real-time traffic statistics are displayed and updated.

 
 
  1. $ sudo apt-get install cbm 

11. speedometer

This is another small and simple tool. It only draws beautiful images and displays inbound and outbound traffic transmitted through an interface.

 
 
  1. $ speedometer -r eth0 -t eth0 

Install speedometer

 
 
  1. # Ubuntu or debian users
  2. $ Sudo apt-get install speedometer

12. pktstat

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

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

13. netwatch

Netwatch is part of the netdiag tool library. It can also display the connections between the local host and other remote hosts, and display the data transmission speeds on each connection.

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

14. trafshow

Like netwatch and pktstat, trafshow can also report the current active connections, the protocols they use, and the data transmission speed on each connection. It can use the pcap Type Filter to filter connections.

Only monitoring TCP connections

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

15. netload

The netload command only displays a brief report about the current traffic load and displays the Total Bytes transmitted since the program was started. There are no more features. It is part of netdiag.

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

16. ifstat

Ifstat can display network bandwidth in batch mode. The output format allows you to use other programs or utilities to log in and analyze logs.

 
 
  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 

Install ifstat: Ubuntu, Debian, and Fedora are available in the default software library. CentOS users need to obtain it from Repoforge because it is not in Epel.

 
 
  1. # ubuntu, debian 
  2. $ sudo apt-get install ifstat 
  3. # fedora, centosRepoforge) 
  4. $ sudo yum install ifstat 

17. dstat

Dstat is a widely used tool written in python. It can monitor different statistics of the system and report data in batch processing mode, you can also log the data to a CSV or similar file. This example shows how to use dstat to report network bandwidth.

Install 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 

18. collectl

Collectl reports system statistics in a format similar to dstat. Like dstat, collectl also collects statistics about different system resources, such as processors, memory, and networks. A simple example 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 

Install collectl

 
 
  1. # Ubuntu/Debian users
  2. $ Sudo apt-get install collectl
  3. # Fedora
  4. $ Sudo yum install collectl

Conclusion

The preceding convenient commands can quickly check the network bandwidth usage on Linux servers. However, these commands require users to log on to the remote server through SSH. In addition, Web-based monitoring tools can also be used to implement the same task.

Ntop and darkstat are two basic Web-based network monitoring tools for Linux systems. In addition, enterprise-level monitoring tools, such as nagios, provide a number of features that not only monitor servers, but also monitor the entire infrastructure.

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.