18 Common commands for monitoring network bandwidth on a Linux server
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.
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-ng, Tcptrack, Pktstat, Netwatch, and Trafshow
- Bandwidth usage for each process ――nethogs
- Nagiosweb------Nagios
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 . The result is bit/s.
- $ nload
Installing Nload:fedora and Ubuntu has nload in the default repositories. CentOS users need to get nload from the Epel Software library.
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.
- $ 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.
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.
- $ sudo iptraf
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.
- $ sudo nethogs
Installing Nethogs:ubuntu, Debian, and fedora users can be obtained from the default repositories. CentOS users are required to Epel.
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.
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 .
- $ slurm-s-I. eth0
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.
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.
- $ Service Vnstat Status
- * Vnstat Daemon is running
Running Vnstat with no options will only show the total amount of data transferred since the daemon was run.
- $ 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 ' 8.19 GiB | 2.08 GiB | 10.27 GiB | 35.60 kbit/s
- Mar ' 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 | 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.
- $ vnstat-l -I Eno1
- Monitoring eth0 ... (press Ctrl-c to stop)
- 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.
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.
- $ 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 the Curses2 output mode to draw a bar chart for traffic.
- $ bwm-ng-o Curses2
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.
Speedometer.
This is another small and simple tool that only draws beautiful graphics that show inbound traffic and outbound traffic over an interface.
- $ speedometer-r eth0-t eth0
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.
- $ sudo pktstat-i eth0-nt
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.
- $ sudo netwatch-e eth0-nt
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
- $ sudo trafshow-i eth0 TCP
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.
- $ netload eth0
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.
- $ 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
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.
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.
- $ 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
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.
- $ 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
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.
Original link: http://www.binarytides.com/linux-commands-monitor-network/
18 Common commands for monitoring network bandwidth on Linux servers nload, Iftop,iptraf-ng, Nethogs, Vnstat. Nagios