iptables 累计(Accounting)

对於每一条规则,核心各自设置两个专属的计数器,用于累计符合该条件的封包数,以及这些封包的总位元组数。这两项资讯可用於统计网路用量。

举例来說,假设有一台Internet闸道器路,eth0接内部网络,eth1接Internet;使用下列规则可使其核心自动累计内外网路所交換的封包数与资料量:
iptables -A FORWARD -i ethl
iptables -A FORWARD -o ethl
iptables -A INPUT -i ethl
iptables -A OUTPUT -o ethl

执行上述命令之后,使用iptable -L -v显示统计结果(注意INPUT和OUTPUT的计数结果 - 非零值表示已经有些网络交通问题发生在我们显示计数结果之前):

Chain INPUT (policy ACCEPT 27 packets, 1728 bytes)
pkts bytes target prot opt in out source destination
3 192 all - - eth1 any anywhere anywhere

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 all - - eth1 any anywhere anywhere
0 0 all - - any eth1 anywhere anywhere

Chain OUTPUT (policy ACCEPT 21 packets, 2744 bytes)
pkts bytes target prot opt in out source destination
3 192 all - - any eth1 anywhere anywhere

在统计方面的应用,请参与《表14》对于 -c、-n、-t和-x选项的讨论,以及《表15》对于-L和-z选项的说明。

posted @ 2019-07-13 11:52  樊伟胜  阅读(277)  评论(0编辑  收藏  举报