LinuxQuestions.org
Help answer threads with 0 replies.
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 05-19-2011, 08:19 AM   #1
fmillion
Member
 
Registered: Nov 2006
Posts: 93

Rep: Reputation: 27
iptables resets counter when rules are added


Hello,

Whenever I add a rule to iptables, all of the policy counters reset. The counters for each individual rule remain intact, however, the main counter resets.

Here's what I mean:

Code:
[root] ~ # iptables -vL
Chain INPUT (policy ACCEPT 65M packets, 83G bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 50M packets, 30G bytes)
 pkts bytes target     prot opt in     out     source               destination

[root] ~ # iptables -A INPUT -s 192.168.1.2 -j DROP
[root] ~ # iptables -vL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       all  --  any    any     192.168.1.2          anywhere

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
As you can see, when I added the rule, the counters under "policy" reset to 0. If I were to add another rule, the counters for the 192.168.1.2 rule would remain intact, but the counters for the policy would again be reset.

Code:
[root] ~ # iptables -vL
Chain INPUT (policy ACCEPT 12M packets, 14G bytes)
 pkts bytes target     prot opt in     out     source               destination
   44  9210 DROP       all  --  any    any     192.168.1.2          anywhere

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 8756K packets, 10G bytes)
 pkts bytes target     prot opt in     out     source               destination

[root] ~ # iptables -A INPUT -s 192.168.1.3 -j DROP
[root] ~ # iptables -vL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
   44  9210 DROP       all  --  any    any     192.168.1.2          anywhere
    0     0 DROP       all  --  any    any     192.168.1.3          anywhere

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
Is this expected behavior? Can it be fixed?

Code:
[root] ~ # iptables -V
iptables v1.4.10
[root] ~ # uname -a
Linux nas 2.6.36 #2 SMP Wed Nov 24 02:36:43 CET 2010 i686 i686 i386 GNU/Linux
Thank you!

-FM

Last edited by fmillion; 05-19-2011 at 08:23 AM. Reason: add illustration for second point
 
Old 05-19-2011, 11:14 AM   #2
andrewthomas
Senior Member
 
Registered: May 2010
Location: Chicago Metro
Distribution: Arch, Gentoo, Slackware
Posts: 1,690

Rep: Reputation: 312Reputation: 312Reputation: 312Reputation: 312
I use counters and have never had this problem.

What you could try is to use insert instead of add.

Code:
iptables -I INPUT 1 -s 192.168.1.2 -j DROP
 
Old 05-19-2011, 11:51 AM   #3
fmillion
Member
 
Registered: Nov 2006
Posts: 93

Original Poster
Rep: Reputation: 27
It appears to occur on insert as well. Anytime the rule chain is modified, in short, it seems to occur.

It's worth noting that adding rules to user-created chains doesn't affect the main chains. I could of course deal with this by using a kluge:

iptables -N INPUT2
iptables -A INPUT -j INPUT2

and working on INPUT2. But that's obviously a silly workaround...

It may be worth noting that this is an LFS system, and I compiled all components from scratch. I was going to check the Netfilter pages to see if this is referenced anywhere, but I believe I did that once before and came up empty-handed...

Further advice, anyone?
 
  


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
Restore iptables Rules that have been saved with iptables-save tiuz Linux - Security 4 08-14-2010 05:50 PM
pppoe-start resets iptables chains homecsiga Linux - Networking 0 09-07-2007 08:27 PM
iptables 1.27a still loading rules after installing iptables 1.3.0 yawe_frek Linux - Software 1 06-07-2007 09:50 PM
iptables resets automaticaly Toni007 Linux - Security 1 01-31-2007 07:45 PM
iptables resets gizza23 Linux - Networking 2 07-09-2005 10:25 AM

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

All times are GMT -5. The time now is 01:37 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