LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 11-15-2004, 06:01 PM   #1
TobyD
LQ Newbie
 
Registered: Feb 2004
Posts: 6

Rep: Reputation: 0
Question IP-Accounting by iptables?


Hi,

is it possible to log the moved (kilo|mega|giga)bytes per ip on every interface by iptables? I'll to see, how many MegaBytes and from where flows trought my routerinterfaces per diem. I don't want any huge statistic tools like mtrg, nagios, etc, only the amount of bytes per diem and per IP.

ie:

Code:
[...]
14.11.2004:
192.168.0.1   23MB
192.168.0.2   42MB

13.11.2004:
192.168.0.1   42MB
192.168.0.2   23MB

[...]
Any Ideas?
THX
TobyD
 
Old 11-15-2004, 06:44 PM   #2
CroMagnon
Member
 
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Here's one idea:

Code:
# Create two new chains with default action of RETURN
iptables -N ether0-out
iptables -A ether0-out -j RETURN
iptables -N ether1-out
iptables -A ether1-out -j RETURN
# Insert rules at the top of the output chain
iptables -I OUTPUT -o eth0 -j ether0-out
iptables -I OUTPUT -o eth1 -j ether1-out
Now when a packet enters the OUTPUT chain, it will be sent to the appropriate rule for that interface, and the RETURN target will drop it right back into the OUTPUT chain again - so the ether0-out chain will have packet counters for all packets that go out on eth0, but will do basically nothing (and shouldn't interfere with any other rules in your OUTPUT chain, if you have any).
Use:
Code:
iptables -L ether0-out -v
to see the stats (for eth0) and
Code:
iptables -Z ether0-out
to reset them for a new day.

You could do something similar for the INPUT or FORWARD chains depending on what you need to monitor.
 
Old 11-15-2004, 06:59 PM   #3
TobyD
LQ Newbie
 
Registered: Feb 2004
Posts: 6

Original Poster
Rep: Reputation: 0
exactly this!

now, i must create one rule for each of my ip and my log could be then:

iptables -nxvL $RULE | awk '{ print $2; }'

many thanks!
TobyD

btw: found this even by google: http://k12linux.mesd.k12.or.us/nag2/...ccounting.html
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Accounting Software gamehack Linux - Software 1 08-16-2004 12:43 PM
iptables traffic accounting for each IP/MAC sheyh Linux - Networking 0 07-11-2004 04:55 PM
iptables accounting rules petrax Linux - Networking 1 11-10-2003 09:09 PM
Traffic accounting...? Gorbachov Linux - Software 2 09-23-2003 07:16 AM
volume accounting Tinkster Linux - Networking 2 01-30-2003 02:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration