咨询热线:4006-75-4006

售前:9:00-23:30    备案:9:00-18:00    技术:7*24h

Linux下如何对端口流量进行统计

2019-05-16 14:31:30 10511次

添加需要统计的端口


1、输入监控


下面示例是监控目标端口是8080的输入流量 --dport(destination port 的缩写)


iptables -A INPUT -p tcp --dport 8080

2、输出监控


下面示例是监控来源端口是8080的输出流量 --sport(source port 的缩写)


iptables -A OUTPUT -p tcp --sport 8080

查看统计数据


iptable -L -v -n -x

示例结果:


8080端口接收的流量为2885字节,发送的流量是8240字节


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

重置统计数据


注意:这里是重置所有端口的统计数据


1、重置所有输入端口


Iptable -Z INPUT

2、重置所有输出端口


Iptable -Z OUTPUT

移除统计端口


1、移除输入端口


iptables -D INPUT -p tcp --dport 8080

2、移除输出端口


iptables -D OUTPUT -p tcp --sport 8080


首页
最新活动
个人中心