终端流量统计

终端流量统计

需求

AP模式下统计无线终端的WAN口流量,本地流量和总流量。

实现

  1. 无线终端的总流量可以通过无线侧实现,apstats -m ‘xx:xx:xx:xx:xx:xx’
  2. 无线终端本地流量需要通过ebtales/iptables监控dst ip到本地地址的包

无线终端总流量

root@A822:~# apstats -s -m 38:A4:ED:A1:DB:AA
Node Level Stats: 38:a4:ed:a1:db:aa (under VAP ath00)
Tx Data Packets                 = 361968
Tx Data Bytes                   = 515616712
Rx Data Packets                 = 379274
Rx Data Bytes                   = 33493226
Tx Unicast Data Packets         = 376701
Average Tx Rate (kbps)          = 11708
Average Rx Rate (kbps)          = 6295
Last tx rate                    = 0
Last rx rate                    = 0
Last mgmt rx rate               = 1000
Rx MIC Errors                   = 0
Rx Decryption errors            = 0
Rx errors                       = 0
Packets Queued                  = 361968
Host Discard                    = 0
Tx failures                     = 406
Rx RSSI                         = 40
Rx MGMT RSSI                    = 35

无线终WAN流量统计实现

  1. 添加一个用户自定义chain来统计总WAN流量
iptables -N wan_uplink_traf
iptables -N wan_downlink_traf
iptables -I FORWARD -j wan_uplink_traf
iptables -I FORWARD -j wan_downlink_traf

iptables -N client_wan_uplink_traf
iptables -N client_wan_downlink_traf

iptables -I wan_uplink_traf -d 10.0.0.0/8 -j RETURN
iptables -I wan_uplink_traf -d 172.16.0.0/12 -j RETURN
iptables -I wan_uplink_traf -d 192.168.0.0/16 -j  RETURN
iptables -A wan_uplink_traf -j client_wan_uplink_traf

iptables -I wan_downlink_traf -s 10.0.0.0/8 -j RETURN
iptables -I wan_downlink_traf -s 172.16.0.0/12 -j RETURN
iptables -I wan_downlink_traf -s 192.168.0.0/16 -j  RETURN
iptables -A wan_downlink_traf -j client_wan_downlink_traf


  1. 添加一个用户跟踪
iptables -I client_wan_uplink_traf -s 192.168.254.118 -m comment --comment "d4:dc:cd:f2:1c:24"
iptables -I client_wan_downlink_traf -d 192.168.254.118 -m comment -- comment "d4:dc:cd:f2:1c:24"

client上线流程

client下线流程

Reference

  1. 私有地址范围
    tcp/ip协议中,专门保留了三个IP地址区域作为私有地址,其地址范围如下:
    10.0.0.0/8:10.0.0.0~10.255.255.255
    172.16.0.0/12:172.16.0.0~172.31.255.255
    192.168.0.0/16:192.168.0.0~192.168.255.255

  2. ebtables/iptables interaction


nicephil@gmail.com – 2017-12-5

posted on 2017-12-06 09:52  nicephil  阅读(726)  评论(0编辑  收藏  举报

导航