From: "Nestor A. Diaz" <nestor@tiendalinux.com>
To: netfilter@vger.kernel.org
Subject: Clarification on the use of the statistic module
Date: Wed, 10 Jul 2013 10:12:07 -0500 [thread overview]
Message-ID: <51DD79C7.3080707@tiendalinux.com> (raw)
Hi Guys.
I am using the statistics module to balance traffic coming from a
network interface into some services running on the same machine, but
distribution don't tend to be equal.
I use the following iptables script for debugging purposes, which
receives a packet and log it according to the statistic module, i also
put a default log entry in case module don't catch it.
# balance
# log prefix=`date +%Y%m%d%H%M%S`
/sbin/iptables -t nat -A prerouting_rule -i eth0 -p tcp --dport 7000 -m
state --state NEW -m statistic --mode nth --every 2 --packet 0 -j LOG
--log-prefix 20130710095901_packet_0
/sbin/iptables -t nat -A prerouting_rule -i eth0 -p tcp --dport 7000 -m
state --state NEW -m statistic --mode nth --every 2 --packet 0 -j ACCEPT
/sbin/iptables -t nat -A prerouting_rule -i eth0 -p tcp --dport 7000 -m
state --state NEW -m statistic --mode nth --every 2 --packet 1 -j LOG
--log-prefix 20130710095901_packet_1
/sbin/iptables -t nat -A prerouting_rule -i eth0 -p tcp --dport 7000 -m
state --state NEW -m statistic --mode nth --every 2 --packet 1 -j ACCEPT
# default
/sbin/iptables -t nat -A prerouting_rule -i eth0 -p tcp --dport 7000 -m
state --state NEW -j LOG --log-prefix 20130710095901_packet_2
/sbin/iptables -t nat -A prerouting_rule -i eth0 -p tcp --dport 7000 -m
state --state NEW -j ACCEPT
Then i run a series of netcat process to test the configuration:
for i in `seq 1 1000`; do echo test | nc 172.16.1.1 7000; done
The results are logged via syslog, then i use a script to process the
result produced:
# Example: Jul 10 09:37:10 asterix kernel: [3712376.281427]
20130710093659_packet_1 IN=eth0 OUT=
MAC=00:22:4d:56:ac:0c:00:27:0e:0e:b2:61:08:00 SRC=172.24.107.59
DST=172.24.107.1 LEN=60 TOS=0x00 PREC=0x00 TTL=64 ID=54795 DF PROTO=TCP
SPT=35341 DPT=7000 WINDOW=14600 RES=0x00 SYN URGP=0
# count_packets.sh
#!/bin/bash
prefix=$1
for i in 0 1 2
do
echo -n "${i}: "
grep ${prefix}_packet_${i} /var/log/iptables.log | wc | awk '{print $1}'
done
And for 1000 packets i got exactly the following every time i run the
script (with a different log prefix off course)
./count_packets.sh 20130710093659
0: 500
1: 250
2: 250
When i was expecting the following result:
0: 500
1: 500
2: 0
What i am doing wrong ?
Thanks.
--
Typed on my key64.org keyboard
Nestor A Diaz
next reply other threads:[~2013-07-10 15:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-10 15:12 Nestor A. Diaz [this message]
2013-07-11 9:10 ` Clarification on the use of the statistic module Pascal Hambourg
2013-07-11 18:49 ` Nestor A. Diaz
2013-07-11 23:15 ` Pascal Hambourg
2013-07-12 16:55 ` Nestor A. Diaz
2013-07-12 6:37 ` Emilio Lazo Zaia
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=51DD79C7.3080707@tiendalinux.com \
--to=nestor@tiendalinux.com \
--cc=netfilter@vger.kernel.org \
/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.