Example analysis of port traffic statistics under Linux

黄舟
Release: 2017-05-27 10:05:11
Original
2004 people have browsed it

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)

iptables -A INPUT -p tcp --dport 8080
Copy after login

2. Output monitoring

The following example is to monitor the output traffic whose source port is 8080--sport(abbreviation of source port)

iptables -A OUTPUT -p tcp --sport 8080
Copy after login

View statistics

iptable -L -v -n -x
Copy after login

Example results:

The traffic received by port 8080 is 2885 bytes, and the traffic sent is 8240 bytes

Chain INPUT (policy ACCEPT 202 packets, 25187 bytes)
  pkts   bytes target   prot opt in   out   source        destination     
   18   2885      tcp -- *   *    0.0.0.0/0      0.0.0.0/0      tcp dpt:8080

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
  pkts   bytes target   prot opt in   out   source        destination     

Chain OUTPUT (policy ACCEPT 184 packets, 45774 bytes)
  pkts   bytes target   prot opt in   out   source        destination     
   12   8240      tcp -- *   *    0.0.0.0/0      0.0.0.0/0      tcp spt:8080
Copy after login

Heavy Reset statistics

Note: Here are the statistics for resetting all ports

1. Reset all input ports

Iptable -Z INPUT
Copy after login

2. Reset all output ports

Iptable -Z OUTPUT
Copy after login

Remove statistics port

1. Remove input port

iptables -D INPUT -p tcp --dport 8080
Copy after login

2. Remove output port

iptables -D OUTPUT -p tcp --sport 8080
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template