Skip to contentSkip to conversation

nat & ip accounting

DISCUSSION Alexandru Coseru 5 participants 10 messages Mar 26, 2003

lore
Share & tools
lore
#0 lore raw

Hello..

I want to see using iptables -L -v the ammount of traffic generated by each of my LAN's IP..

i have masq 192.168.0.2 to 192.168.0.50...

and now i want to see the traffic generated by 192.168.0.4 since the last reset of counters..

How can I do that ? I want to be able to see the download and the upload ...

Thanks..
Alex

#1 lore raw
Quoted 5 lines · Alexandru Coseru

Hello..

I want to see using iptables -L -v the ammount of traffic generated by each of my LAN's IP..

Quoted 8 lines

i have masq 192.168.0.2 to 192.168.0.50...

and now i want to see the traffic generated by 192.168.0.4 since the last reset of counters..

How can I do that ? I want to be able to see the download and the upload
...

ifconfig

/Kim

#2 lore raw
Quoted 7 lines
Quoted 2 lines

and now i want to see the traffic generated by 192.168.0.4

since the

Quoted 4 lines

last reset of counters..

How can I do that ? I want to be able to see the download and the upload ...

I have an answer but you also got me thinking. A good tool to keep track of traffic via ip addresses would be mrtg. However is there an mrtg type tool that uses the counters in iptables rules to keep track of traffic and output it in a user friendly form.

#6 lore raw
In reply to Kim Jensen
Quoted 8 lines · Kim Jensen
Quoted 7 lines · Alexandru Coseru

Hello..

I want to see using iptables -L -v the ammount of traffic generated by each of my LAN's IP..

i have masq 192.168.0.2 to 192.168.0.50...

Quoted 7 lines
Quoted 6 lines

and now i want to see the traffic generated by 192.168.0.4 since the last reset of counters..

How can I do that ? I want to be able to see the download and the upload
...

ifconfig

ifconfig is the worst alternative, because it regularly resets its counters.

As Rowan suggested, use MRTG [1] or some other tool (RRDtool [2], perhaps? :) to read the statistics.

You may use MRTG with an SNMP daemon on your system or with an iptables extract script [3].

Hope this helps;

Bjørn

[1] http://www.mrtg.org/
[2] http://www.rrdtool.org/
[3] http://www.norris160.org/cisco/MRTG_Monitor_Software.htm

#3 lore raw
In reply to Rowan Reid
Quoted 4 lines · Rowan Reid

I have an answer but you also got me thinking. A good tool to keep track of traffic via ip addresses would be mrtg. However is there an mrtg type tool that uses the counters in iptables rules to keep track of traffic and output it in a user friendly form.

If you wish to see things in a more user friendly way (or usable way, as no system is friendly :-) can be hard as you have to define what in what you wish to see things!

mrtg is quite good, since you get the results on a webpage, but for tracking ip specific things - I don't know, as I don't think the kernel remembers this statistic. You can read per interface but not from each ip connecting to an interface.

/Kim

#7 lore raw
In reply to Bjorn Ruberg
Quoted 17 lines · Bjorn Ruberg
Quoted 8 lines · Kim Jensen
Quoted 7 lines · Alexandru Coseru

Hello..

I want to see using iptables -L -v the ammount of traffic generated by each of my LAN's IP..

i have masq 192.168.0.2 to 192.168.0.50...

Quoted 7 lines
Quoted 5 lines

and now i want to see the traffic generated by 192.168.0.4 since the last reset of counters..

How can I do that ? I want to be able to see the download and the upload ...

ifconfig

Quoted 9 lines

ifconfig is the worst alternative, because it regularly resets its counters.

As Rowan suggested, use MRTG [1] or some other tool (RRDtool [2], perhaps? :) to read the statistics.

You may use MRTG with an SNMP daemon on your system or with an iptables extract script [3].

Well, I tried to be a little provocative with my remark on ifconfig - seems like it worked. MRTH is a much preferred tool. If the problem is that certain persons are having a very high load, then use host based limiting rules.

/Kim

#4 lore raw
In reply to Kim Jensen

If you havn't to many diferent ip/ip-ranges to monitor you can enter iptables filter rules for that ips with no action, just to count the trafic, than use a script and mrtg to show them. something like:

iptables -A FORWARD -s [MonitoredIP] -i [NIC_conecting_to_IP] iptables -A FORWARD -d {MonitoredIP] -o [NIC_conecting_to_IP]

make a script to grab the bytecount and output them as mrtg expect (IN,OUT,UPTIME,HOSTNAME). Change ^[1,2] to select your rules in the chain where you grab the trafic.

iptables -nvxL FORWARD --line-numbers|egrep ^[1,2]|awk '{print $3}'

Cópia Kim Jensen <[email protected]>:

Quoted 24 lines · Rowan Reid
Quoted 3 lines

I have an answer but you also got me thinking. A good tool to keep track of traffic via ip addresses would be mrtg. However is there an mrtg type tool that uses the counters in iptables rules to keep track

of

Quoted 1 line

traffic and output it in a user friendly form.

If you wish to see things in a more user friendly way (or usable way, as no
system is friendly :-) can be hard as you have to define what in what you
wish to see things!

mrtg is quite good, since you get the results on a webpage, but for tracking
ip specific things - I don't know, as I don't think the kernel remembers this
statistic. You can read per interface but not from each ip connecting to an
interface.

/Kim

#5 lore raw
In reply to Kim Jensen
Quoted 6 lines · Kim Jensen
Quoted 4 lines · Rowan Reid

I have an answer but you also got me thinking. A good tool to keep track of traffic via ip addresses would be mrtg. However is there an mrtg type tool that uses the counters in iptables rules to keep track of traffic and output it in a user friendly form.

Quoted 8 lines

If you wish to see things in a more user friendly way (or usable way, as no system is friendly :-) can be hard as you have to define what in what you wish to see things!

mrtg is quite good, since you get the results on a webpage, but for tracking ip specific things - I don't know, as I don't think the kernel remembers this statistic. You can read per interface but not from each ip connecting to an interface.

You can indeed log from each IP connecting. In fact you may read whatever you configure iptables to log. You may end up with one heck of a ruleset, as you need one iptables rule for every different parameter you want to log.

Bjørn

#8 lore raw
In reply to Alexandru Coseru
Quoted 11 lines · Alexandru Coseru

Hello..

I want to see using iptables -L -v the ammount of traffic generated by each of my LAN's IP..

i have masq 192.168.0.2 to 192.168.0.50...

and now i want to see the traffic generated by 192.168.0.4 since the last reset of counters..

How can I do that ? I want to be able to see the download and the upload ...

You will need to create an iptables rule for the specific IP, one for outgoing and one for incoming traffic. Iptables is not able to give you this information if you have not instructed it to store the specific IP's connection. First the rules, then the statistics.

For your future logging requirements:

iptables -A FORWARD -d 192.168.0.4 -j RETURN
iptables -A FORWARD -s 192.168.0.4 -j RETURN

will create two new lines of traffic statistics to read from when running "iptables -L -v", giving you information to and from the given host, respectively. Be sure to put them somewhere early in your rule set.

The RETURN target passes the packets back to the rest of the iptables rule set after having counted them. Thus, these lines do not affect the functionality of your iptables rules.

Bjørn

#9 lore raw
In reply to Alexandru Coseru

Oops, a little error in my last posting. Do NOT use the RETURN target on the default chain.

The RETURN target (obviously) returns the packets to the chain that sent it there. If used in the main chain, it is the same as falling back to the default behaviour of the chain and will hopefully be denied. Therefore, a direction to a chain must be done.

iptables -N count_in
iptables -A count_in -j RETURN

iptables -N count_out
iptables -A count_out -j RETURN

iptables -A FORWARD -s 192.168.0.4 -j count_in iptables -A FORWARD -d 192.168.0.4 -j count_out

will do the trick.

Bjørn