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.
- $ 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.
- # Fedora or centos
- $ Yum install nload-y
- # Ubuntu/debian
- $ 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.
- $ 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.
- # Fedora or centos
- Yum install iftop-y
- # Ubuntu or debian
- $ 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.
- $ sudo iptraf
Install iptraf:
- # Centos basic software library)
- $ Yum install iptraf
- # Fedora or centos with epel)
- $ Yum install iptraf-ng-y
- # Ubuntu or debian
- $ 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.
- $ sudo nethogs
Install nethogs: Ubuntu, Debian, and Fedora can be obtained from the default software library. For CentOS users, Epel is required.
- # Ubuntu or debian default software library)
- $ Sudo apt-get install nethogs
- # Fedora or centos from epel)
- $ 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.
- # Ubuntu or debian
- $ Sudo apt-get install bmon
- # Fedora or centos from repoforge)
- $ 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.
- $ slurm -s -i eth0
Install slurm
- # Debian or ubuntu
- $ Sudo apt-get install slurm
- # Fedora or centos
- $ 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.
- # Ubuntu and debian
- $ Sudo apt-get install tcptrack
- # Fedora, centos from repoforge software library)
- $ 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.
- $ service vnstat status
- * vnStat daemon is running
Running vnstat without any options only displays the total amount of data transmitted since the daemon is running.
- $ vnstat
- Database updated: Mon Mar 17 15:26:59 2014
- eth0 since 06/12/13
- rx: 135.14 GiB tx: 35.76 GiB total: 170.90 GiB
- monthly
- rx | tx | total | avg. rate
-
- ------------------------+-------------+-------------+-------------
- Feb '14 8.19 GiB | 2.08 GiB | 10.27 GiB | 35.60 kbit/s
- Mar '14 4.98 GiB | 1.52 GiB | 6.50 GiB | 37.93 kbit/s
- ------------------------+-------------+-------------+-------------
- estimated 9.28 GiB | 2.83 GiB | 12.11 GiB |
- daily
- rx | tx | total | avg. rate
- ------------------------+-------------+-------------+-------------
- yesterday 236.11 MiB | 98.61 MiB | 334.72 MiB | 31.74 kbit/s
- today 128.55 MiB | 41.00 MiB | 169.56 MiB | 24.97 kbit/s
- ------------------------+-------------+-------------+-------------
- 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.
- $ vnstat -l -i eth0
- Monitoring eth0... (press CTRL-C to stop)
- 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
- # Ubuntu or debian
- $ Sudo apt-get install vnstat
- # Fedora or centos from epel)
- $ 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.
- $ bwm-ng
- bwm-ng v0.6 (probing every 0.500s), press 'h' for help
- input: /proc/net/dev type: rate
- / iface Rx Tx T
- ot=================================================================
- == eth0: 0.53 KB/s 1.31 KB/s 1.84
- KB lo: 0.00 KB/s 0.00 KB/s 0.00
- KB-------------------------------------------------------------------------------------------------------------
- total: 0.53 KB/s 1.31 KB/s 1.84
- KB/s
If the console is large enough, bwm-ng can also use curses2 output mode to draw a bar chart for traffic.
- $ bwm-ng -o curses2
Install bwm-ng: On CentOS, you can install bwm-ng from Epel.
- # Ubuntu or debian
- $ Sudo apt-get install bwm-ng
- # Fedora or centos from epel)
- $ 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.
- $ 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.
- $ speedometer -r eth0 -t eth0
Install speedometer
- # Ubuntu or debian users
- $ 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.
- $ sudo pktstat -i eth0 -nt
- $ 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.
- $ sudo netwatch -e eth0 -nt
- $ 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
- $ sudo trafshow -i eth0 tcp
- $ 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.
- $ netload eth0
- $ 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.
- $ ifstat -t -i eth0 0.5
- Time eth0
- HH:MM:SS KB/s in KB/s out
- 09:59:21 2.62 2.80
- 09:59:22 2.10 1.78
- 09:59:22 2.67 1.84
- 09:59:23 2.06 1.98
- 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.
- # ubuntu, debian
- $ sudo apt-get install ifstat
- # fedora, centosRepoforge)
- $ 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
- $ dstat -nt
- -net/total- ----system----
- recv send| time
- 0 0 |23-03 10:27:13
- 1738B 1810B|23-03 10:27:14
- 2937B 2610B|23-03 10:27:15
- 2319B 2232B|23-03 10:27:16
- 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.
- $ collectl -sn -oT -i0.5
- waiting for 0.5 second sample...
- # <----------Network---------->
- #Time KBIn PktIn KBOut PktOut
- 10:32:01 40 58 43 66
- 10:32:01 27 58 3 32
- 10:32:02 3 28 9 44
- 10:32:02 5 42 96 96
- 10:32:03 5 48 3 28
Install collectl
- # Ubuntu/Debian users
- $ Sudo apt-get install collectl
- # Fedora
- $ 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.