This article mainly introduces how to count port traffic under Linux. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor and take a look.
To monitor and count the program’s exposed port traffic without modifying the source code, you can use the Iptable that comes with Linux to add simple rules to allow it to perform port traffic statistics. role. However, it should be noted that the statistics will be reset to zero when the server is restarted and the Iptable service is restarted.
Add the port that needs statistics
1. Input monitoring
The following example is to monitor the input traffic whose target port is 8080--dport(destination port Abbreviation of source port)
1 |
|
2. Output monitoring
The following example is to monitor the output traffic whose source port is 8080--sport(abbreviation of source port)
1 |
|
View statistics
1 |
|
Example results:
The traffic received by port 8080 is 2885 bytes, and the traffic sent is 8240 bytes
1 2 3 4 5 6 7 8 9 10 |
|
Heavy Reset statistics
Note: Here are the statistics for resetting all ports
1. Reset all input ports
1 |
|
2. Reset all output ports
1 |
|
Remove statistics port
1. Remove input port
1 |
|
2. Remove output port
1 |
|
The above is the detailed content of Example analysis of port traffic statistics under Linux. For more information, please follow other related articles on the PHP Chinese website!