Skip to contentSkip to conversation

Match Patterns in POSTROUTING Table and output it

DISCUSSION pevee 2 participants 2 messages Oct 1, 2002 – Oct 2, 2002

lore
Share & tools
lore

pevee

author
#0 lore raw

Hi,

Hope that this will be post to the mailing list. My task is to

(1) Read a set of IPs from a configuration file
(2) Match this set of IPs with all the entry in POSTROUTING chain
(3) IF any entry that matches criterias (pkts > 10000 AND bytes > 30M), output the entries into a file.
(4) All in all:-

INPUT:- Host IPs
OUTPUT:- pkts and bytes of that Host

Example:-

Chain POSTROUTING (policy ACCEPT 16M packets, 15G bytes)

 pkts bytes target     prot opt in     out     source               destination
93643   33M MARK       tcp  --  *      eth1    0.0.0.0/0            192.168.8.250      MARK set 0x2
    0     0 MARK       all  --  *      eth1    0.0.0.0/0            192.168.250.75     MARK set 0x3
    0     0 MARK       all  --  *      eth1    0.0.0.0/0            192.168.250.75     MARK set 0x3
    0     0 MARK       all  --  *      eth1    0.0.0.0/0            192.168.250.75     MARK set 0x3
    0     0 MARK       all  --  *      eth1    0.0.0.0/0            192.168.250.75     MARK set 0x3

My questions are:-

(1) Can I do this with current iptables?
(2) If not? Should I start writting extension for iptables? Which documentation can get me get started?

Hope to hear from you soon :)
Thank you

Warm regards,

Calvin

#1 lore raw
Quoted 9 lines · pevee

Hi,

Hope that this will be post to the mailing list. My task is to

(1) Read a set of IPs from a configuration file
(2) Match this set of IPs with all the entry in POSTROUTING chain
(3) IF any entry that matches criterias (pkts > 10000 AND bytes > 30M), output the entries into a file.

Quoted 5 lines

My questions are:-

(1) Can I do this with current iptables?
(2) If not? Should I start writting extension for iptables? Which documentation can get me get started?

Yes, you should have all the information you need to write some fancy scripts to do this, if you use iptables -L POSTROUTING -v -n -x to get your packets &
byte counters. The -n option makes sure you have numeric IP addresses in
the rules (not hostnames) and the -x option shows the exact count value for the packet / byte counts, instead of being abbreviated with things like M and G.

I'd suggest you start with something like:
iptables -L POSTROUTING -n -v -x | grep -f IPlist
and then feed the result into a Perl script (or maybe awk if you're happier with that ?), but there will be many different ways of achieving it.

Antony.

Signature · 3 lines
Documentation is like sex:
when it's good, it's very very good;
when it's bad, it's still better than nothing.