<html><br>
I want to measure the amount of traffic (Linux) on port 80 (Tomcat)
<br>
separated by incoming and outgoing. I figure maybe I can do this
<br>
(after creating the chains):
<br>
<br><font face="courier new,courier">
iptables -A INPUT -d 10.0.0.50 -p tcp -m tcp --dport 80 -j COUNTIN
<br>
iptables -A INPUT -s 10.0.0.50 -p tcp -m tcp --sport 80 -j COUNTOUT
<br>
iptables -A COUNTIN -j ACCEPT
<br>
iptables -A COUNTOUT -j ACCEPT
<br></font>
<br>
and then do an iptables -L -nv tp count the bytes. This gives output
<br>
like this:
<br>
<br><blockquote><font face="courier new,courier">
Chain INPUT (policy ACCEPT 510M packets, 26G bytes)
</font><br><font face="courier new,courier">
pkts bytes target prot opt in out source destination
</font><br><font face="courier new,courier">
365 29891 COUNTIN tcp -- * * 0.0.0.0/0 10.0.0.50
</font><br><font face="courier new,courier">
tcp dpt:80
</font><br><font face="courier new,courier">
0 0 COUNTOUT tcp -- * * 10.0.0.50 0.0.0.0/0
</font><br><font face="courier new,courier">
tcp spt:80
</font><br><font face="courier new,courier">
...
</font><br><font face="courier new,courier">
...
</font><br><font face="courier new,courier">
Chain COUNTIN (1 references)
</font><br><font face="courier new,courier">
pkts bytes target prot opt in out source destination
</font><br><font face="courier new,courier">
365 29891 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0
</font><br><br><font face="courier new,courier">
Chain COUNTOUT (1 references)
</font><br><font face="courier new,courier">
pkts bytes target prot opt in out source destination
</font><br><font face="courier new,courier">
0 0 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0
</font><br></blockquote>
<br>
<br>
<br>
Now a couple questions.
<br>
<br>
1. Will this screw up normal TCP/UDP behavior? It does not seem to.
<br>
<br>
2. Do I need to do the "ACCEPT" lines? Will normal TCP and IP still
<br>
work? It seems like I need it for 2 reasons:
<br>
1 - So the packets actually get accepted. But maybe they will anyway?
<br>
2 - When I use -Z (like iptables -Z COUNTIN) to zero the chain, if I
<br>
don't have the -j ACCEPT those two chains won't be listed and I can't
<br>
zero the chains. I can zero INPUT but that will zero all INPUT.
<br>
(Now that I think of it, COUNTOUT should be on OUTPUT not INPUT but
<br>
the same question applies)
<br><br>It is easier to grep "COUNTIN tcp" and get the first 2 fields than<br>grepping for "Chain COUNTIN", reading 2 lines and then getting<br>the fields (which I suppose could be done with awk).<br>
<br>
</html>