All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vlado Drz(ík" <vlado@ttx.sk>
To: Payam Chychi <pchychi@gmail.com>
Cc: Richard Hartmann <richih.mailinglist@gmail.com>,
	netfilter@vger.kernel.org
Subject: Re: (Ab)using iptables to record byte count per IP?
Date: Sat, 10 Jan 2009 00:27:14 +0100	[thread overview]
Message-ID: <4967DD52.2050904@ttx.sk> (raw)
In-Reply-To: <f08c15d10901090723h3c3f0edbhbc4dfe674fbd653b@mail.gmail.com>

It depends on number of IPs that you want to account and what traffic
(pck/s) will be comming through your router.
The IP tables accouning based on adding IPs to chains (iptables -A
somechain -s <src_IP>) is simple but scales well just for small packet
counts and number of rules.
But for you it's probably best choice as it's really easy to implement.
For example create 2 tables:
iptables -N ACCT_IN
iptables -N ACCT_OUT

Add to forward somewhere before accepting rules (nearly begening of chain):
iptables -A FORWARD -i <inet_nic> -j ACCT_IN
iptables -A FORWARD -o <inet_nic> -j ACCT_OUT
Add IP addreses
iptables -A ACCT_IN -d <ipaddress 1> -j RETURN
iptables -A ACCT_IN -d <ipaddress 2> -j RETURN
....
Add oposite diraction:
iptables -A ACCT_OUT -s <ipaddress 1> -j RETURN
iptables -A ACCT_OUT -s <ipaddress 2> -j RETURN


If you are going to count many users >1000 it's better to consider
external modules like ipt_ACCCOUNT:
http://www.intra2net.com/de/produkte/opensource/ipt_account/
It scales very well for large numbers of IPs but bigest drawback is that
it's out of tree module and you need to compile kernel+iptables (so it's
really not a option for you).

If I understand the conntrack (CT) accounting correctly I see that there
is problem that it's flow based so if some flows are dismissed from CT
table quickly you can get unaccurate results if you read CT table in
wider intervals.

I'd much like to see also packet based accounting (not just flow based
one) in kernel. Do someone use conntrack based accounting in real life?

- vlado

Payam Chychi  wrote / napísal(a):
> Hi,
> 
> Thats possible by using the pre-nat table. You will need to place an
> accept all rule for each individual /32 ip address that you want to do
> accounting for ( I use accept so that I can see all traffic destined
> for the ip)
> 
> -Payam
> 
> 
> On Fri, Jan 9, 2009 at 3:27 AM, Richard Hartmann
> <richih.mailinglist@gmail.com> wrote:
>> Hi all,
>>
>> I need to log the traffic each local IP in a NAT'ed network generates
>> per day.
>>
>> Unfortunately, the environment is rather restricted and compiling new
>> software is not an option. Thus, I am wondering if I can abuse iptables,
>> which is in use anyway, to log for me, as well.
>>
>> The end result should be a log which contains IP, date and traffic
>> generated. I don't really care about the output format as I will perl it
>> into the format I need, anyway.
>>
>>
>> Thanks for all input,
>> Richard
>> --
>> To unsubscribe from this list: send the line "unsubscribe netfilter" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>>
> 
> 
> 


  reply	other threads:[~2009-01-09 23:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-09 11:27 (Ab)using iptables to record byte count per IP? Richard Hartmann
2009-01-09 11:50 ` Artūras Šlajus
2009-01-09 11:55   ` Thomas Jacob
2009-01-09 12:46     ` Richard Hartmann
2009-01-10  2:55     ` Amos Jeffries
2009-01-09 12:44   ` Richard Hartmann
2009-01-09 17:10     ` Robert Nichols
2009-01-09 12:35 ` Pablo Neira Ayuso
2009-01-09 12:47   ` Richard Hartmann
2009-01-09 15:23 ` Payam Chychi
2009-01-09 23:27   ` Vlado Drz(ík [this message]
2009-01-09 16:36 ` Peter Renzland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4967DD52.2050904@ttx.sk \
    --to=vlado@ttx.sk \
    --cc=netfilter@vger.kernel.org \
    --cc=pchychi@gmail.com \
    --cc=richih.mailinglist@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.