* noob question howto using iptables limit ip access times
@ 2010-06-21 11:30 Zhu Jing
2010-06-21 11:53 ` /dev/rob0
2010-06-21 12:02 ` Pascal Hambourg
0 siblings, 2 replies; 5+ messages in thread
From: Zhu Jing @ 2010-06-21 11:30 UTC (permalink / raw)
To: netfilter
hi ,all
My aim is limit ip access to my squid server with 1000 times per day.
If this ip connections counts more then 1000,iptables will drop it.
I have google a lot,and write a wired scripts :P
===========
#!/bin/sh
iptables -F
iptables -X
iptables -Z
iptables -N squid
iptables -A INPUT -p tcp --dport 80 -j squid
iptables -A squid -m limit --limit 1/hour --limit-burst 1000 -j RETURN
iptables -A squid -j DROP
service iptables save
service iptables restart
==========
iptables -A squid -m limit --limit 1/hour --limit-burst 1000 -j RETURN
IMO: this rule means ,the limit-burst token bucket is set to 1000
initially, for each hour token count goes up by 1, when token bucket
is empty---> not match --> go next rule
But, I tested it by using IE refresh my server , when i refresh
more then 7 or 8 times ,iptables going to drop my connections, why?
CentOS4.6,kernel 2.6.9,iptables v1.3.5
Im so sorry for my bad English,hope your understand what i was saying
Any reply, webslink, experience ,doc and tools are highly appreciable!!
Regards
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: noob question howto using iptables limit ip access times
2010-06-21 11:30 noob question howto using iptables limit ip access times Zhu Jing
@ 2010-06-21 11:53 ` /dev/rob0
2010-06-21 12:02 ` Pascal Hambourg
1 sibling, 0 replies; 5+ messages in thread
From: /dev/rob0 @ 2010-06-21 11:53 UTC (permalink / raw)
To: netfilter
On Mon, Jun 21, 2010 at 07:30:32PM +0800, Zhu Jing wrote:
> My aim is limit ip access to my squid server with 1000 times per day.
> If this ip connections counts more then 1000,iptables will drop it.
snip
> iptables -A squid -m limit --limit 1/hour --limit-burst 1000 -j RETURN
>
> IMO: this rule means ,the limit-burst token bucket is set to 1000
> initially, for each hour token count goes up by 1, when token bucket
> is empty---> not match --> go next rule
No, the burst is the number of packets arriving at once. I think you
want:
iptables -A squid -m limit --limit 1000/day -j RETURN
optionally with a reasonable burst limit: --limit-burst 100
See also the more featureful connlimit and hashlimit matches. Perhaps
-m recent might meet your need, too.
--
Offlist mail to this address is discarded unless
"/dev/rob0" or "not-spam" is in Subject: header
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: noob question howto using iptables limit ip access times
2010-06-21 11:30 noob question howto using iptables limit ip access times Zhu Jing
2010-06-21 11:53 ` /dev/rob0
@ 2010-06-21 12:02 ` Pascal Hambourg
2010-06-21 14:58 ` Curby
1 sibling, 1 reply; 5+ messages in thread
From: Pascal Hambourg @ 2010-06-21 12:02 UTC (permalink / raw)
To: Zhu Jing; +Cc: netfilter
Hello,
Zhu Jing a écrit :
>
> My aim is limit ip access to my squid server with 1000 times per day.
> If this ip connections counts more then 1000,iptables will drop it.
>
> I have google a lot,and write a wired scripts :P
>
> ===========
> #!/bin/sh
> iptables -F
> iptables -X
> iptables -Z
> iptables -N squid
> iptables -A INPUT -p tcp --dport 80 -j squid
> iptables -A squid -m limit --limit 1/hour --limit-burst 1000 -j RETURN
> iptables -A squid -j DROP
> service iptables save
> service iptables restart
> ==========
>
> iptables -A squid -m limit --limit 1/hour --limit-burst 1000 -j RETURN
>
> IMO: this rule means ,the limit-burst token bucket is set to 1000
> initially, for each hour token count goes up by 1, when token bucket
> is empty---> not match --> go next rule
> But, I tested it by using IE refresh my server , when i refresh
> more then 7 or 8 times ,iptables going to drop my connections, why?
Because your rule limits packets, not connections. A single TCP
connection involves multiple packets.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: noob question howto using iptables limit ip access times
2010-06-21 12:02 ` Pascal Hambourg
@ 2010-06-21 14:58 ` Curby
2010-06-22 4:38 ` Zhu Jing
0 siblings, 1 reply; 5+ messages in thread
From: Curby @ 2010-06-21 14:58 UTC (permalink / raw)
To: Pascal Hambourg; +Cc: Zhu Jing, netfilter
On Mon, Jun 21, 2010 at 6:02 AM, Pascal Hambourg
<pascal.mail@plouf.fr.eu.org> wrote:
> Because your rule limits packets, not connections. A single TCP
> connection involves multiple packets.
Yes, the stateful features of netfilter would be useful here. Drop
the INVALIDs, accept the ESTABLISHED,RELATED, drop NEW not SYN
packets, and your match will mostly match valid new connection
attempts. This could be further improved by detecting and dropping
port scans, as Jan wrote about.
This prevents the 1000/day rule from matching packets for ESTABLISHED
connections and for spurious packets that should be ignored.
--Mike
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: noob question howto using iptables limit ip access times
2010-06-21 14:58 ` Curby
@ 2010-06-22 4:38 ` Zhu Jing
0 siblings, 0 replies; 5+ messages in thread
From: Zhu Jing @ 2010-06-22 4:38 UTC (permalink / raw)
To: Curby, rob0; +Cc: Pascal Hambourg, netfilter
On Mon, Jun 21, 2010 at 22:58, Curby <curby@cur.by> wrote:
>
> On Mon, Jun 21, 2010 at 6:02 AM, Pascal Hambourg
> <pascal.mail@plouf.fr.eu.org> wrote:
> > Because your rule limits packets, not connections. A single TCP
> > connection involves multiple packets.
>
> Yes, the stateful features of netfilter would be useful here. Drop
> the INVALIDs, accept the ESTABLISHED,RELATED, drop NEW not SYN
> packets, and your match will mostly match valid new connection
> attempts. This could be further improved by detecting and dropping
> port scans, as Jan wrote about.
>
> This prevents the 1000/day rule from matching packets for ESTABLISHED
> connections and for spurious packets that should be ignored.
>
> --Mike
Thank your very much, ill try it later .Thx a lot
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-06-22 4:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-21 11:30 noob question howto using iptables limit ip access times Zhu Jing
2010-06-21 11:53 ` /dev/rob0
2010-06-21 12:02 ` Pascal Hambourg
2010-06-21 14:58 ` Curby
2010-06-22 4:38 ` Zhu Jing
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.