For Linux, we often need to check the traffic of Linux traffic monitoring. Linux traffic monitoring is still quite common. So I studied some methods of Linux traffic monitoring, I would like to share it with you here and hope it will be useful to you. The following three methods can be used to view the current traffic.
Iftop tool for Linux traffic monitoring
Purpose: monitors the network status and bandwidth used by each ip address in real time.
Run the command (must be root)
Monitor network card Traffic of eth1
# Iftop-I eth1
Traffic is displayed in bytes (by default, bits ):
$ Iftop-B
The IP address is displayed directly without reverse DNS resolution:
$ Iftop-n
The connection port number is displayed directly, but the service name is not displayed:
$ Iftop-N
Display inbound and outbound traffic of a CIDR Block
$ Iftop-F 192.168.1.0/24 or 192.168.1.0/255.255.255.0
For other parameters, see iftop-h.
When you enter the iftop screen, you can press p to switch whether to display the connection port, n to switch to display the IP address or the domain name of the host, N to switch to display the connection port code or name, and p to suspend display, switch B to check whether the display bar is displayed. Switch B to calculate the average traffic in a few seconds. Other buttons can be clicked h to view the description.
Set the region ~ /. Iftoprc. You can refer to the info page of iftop if you set the limit method.
Linux traffic monitoring nload Tool
Purpose: monitors the network status and bandwidth used by each ip address in real time (nonsense)
The default nload is the eth0 Nic. If you want to monitor the traffic of the eth1 Nic
# Nload eth1
By default, nload is divided into two parts: the upper part is: Incoming, that is, the traffic into the NIC, the lower part is: Outgoing, that is, the traffic from this Nic, each part has the current traffic Curr), average traffic Avg), minimum traffic Min), maximum traffic Max), and total traffic Ttl), which looks quite intuitive.
In addition, you can also define the unit of Traffic Value display.
# Nload -- help
You can see the specific parameters.
View average network traffic
The following script can monitor the average traffic of your network. You can set the time.
#! /Bin/bash
Echo-n "which nic? "
Read eth
Echo "the nic is" $ eth
Echo-n "how much seconds :"
Read sec
Echo "duration is" $ sec "seconds, wait please ..."
Infirst = $ (awk '/' $ eth '/{print $1}'/proc/net/dev | sed's/'$ eth '://')
Outfirst = $ (awk '/' $ eth '/{print $10}'/proc/net/dev)
Sumfirst = $ ($ infirst + $ outfirst ))
Sleep $ sec "s"
Inend = $ (awk '/' $ eth '/{print $1}'/proc/net/dev | sed's/'$ eth '://')
Outend = $ (awk '/' $ eth '/{print $10}'/proc/net/dev)
Sumend = $ ($ inend + $ outend ))
Sum = $ ($ sumend-$ sumfirst ))
Echo $ sec "seconds total:" $ sum "bytes"
Aver = $ ($ sum/$ sec ))
Echo "avrage:" $ aver "bytes/sec"
- Management information library MIB in Linux SNMP) Learning
- There are two methods for collecting data in Linux SNMP:
- Seven BT download software collections in Linux
- Thirteen powerful Linux performance monitoring tools
- Learn Linux and FreeBSD to share swap partitions