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


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

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


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.


14.11.2004:   23MB   42MB

13.11.2004:   42MB   23MB

Any Ideas?
Old 11-15-2004, 06:44 PM   #2
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
Here's one idea:

# 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).
iptables -L ether0-out -v
to see the stats (for eth0) and
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
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!

btw: found this even by google:


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 > Forums > Linux Forums > Linux - Networking

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

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