Rss Feed
Tweeter button
Facebook button
Linkedin button
Digg button
Youtube button
24 Feb
2009
Posted in: Linux
By    No Comments

Bandwidth monitoring using iptables

It was a new info for  me that bandwidh can be monitored using Iptables. Well, I tried it and worked fine.

If you want to try this, here are the steps.

Most of the time we use iptables to set up a firewall on a machine, but iptables also provides packet and byte counters.

Every time an iptables rule is matched by incoming or outgoing data streams, the software tracks the number of packets and the

amount of data that passes through the rules.

First, we can create a custom chain, say bandwidth

iptables -N bandwidth

iptables -A INPUT -d <ip> -j bandwidth

iptables -A bandwidth -d <ip>

Bandwidth statistics

Viewing the current bandwidth usage is a matter of running iptables with the -L and -v options. The -L outputs the statistics for a

chain (or all chains if none is provided). The -v option provides verbose output, including the packet and byte counters that we are interested in

iptables -n -V -L

[root@server1 ~]# iptables -n -L -v
Chain INPUT (policy ACCEPT 447 packets, 164K bytes)
pkts bytes target     prot opt in     out     source               destination
265 53063 bandwidth  all  –  venet0 *       0.0.0.0/0            69.197.157.245


So, what do you think?