使用iptables进行非路由器机器的带宽监视

我在这里遇到了这个教程,介绍了如何使用iptables监视带宽。 我想适应一个非路由器的机器,所以我想知道有多less数据正在进出,而不是通过。

这里是我添加的规则:

iptables -N ETH0_IN iptables -N ETH0_OUT iptables -I INPUT -i eth0 -j ETH0_IN iptables -I OUTPUT -o eth0 -j ETH0_OUT 

这里是一个输出示例:

 user@host:/tmp$ sudo iptables -x -vL -n Chain INPUT (policy ACCEPT 1549 packets, 225723 bytes) pkts bytes target prot opt in out source destination 199 54168 ETH0_IN all -- eth0 * 0.0.0.0/0 0.0.0.0/0 Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 1417 packets, 178128 bytes) pkts bytes target prot opt in out source destination 201 19597 ETH0_OUT all -- * eth0 0.0.0.0/0 0.0.0.0/0 Chain ETH0_IN (1 references) pkts bytes target prot opt in out source destination Chain ETH0_OUT (1 references) pkts bytes target prot opt in out source destination 

如上所示,ETH0_IN和ETH0_OUT没有数据包和字节值,这与我引用的教程中的结果并不相同。

我在某个地方犯了一个错误吗? 谢谢你的时间。

创build一个匹配所有stream量的术语,但不做任何事情(但是数量):

 iptables -A ETH0_IN iptables -A ETH0_OUT 

在您的教程中,您的自定义链包含类似的条目 – 无论您喜欢什么types的会计。 (每个IP,每个协议…)

如果你只是考虑input/输出stream量,不做转发(我从“非路由器机器”读取的),得到接口计数器:

 # ifconfig eth0 | grep 'RX bytes' RX bytes:7029377146 (7.0 GB) TX bytes:923972351 (923.9 MB) 

如果你只是做一个总,你甚至可以保存自定义链,做

 iptables -A INPUT -i eth0 iptables -A OUTPUT -o eth0 

让你的柜台….