Skip to contentSkip to conversation

quota and time patch.

DISCUSSION SB CH 3 participants 4 messages Sep 27, 2002

lore
Share & tools
lore

SB CH

author
#0 lore raw

Hello all.

I would like to limit the traffic usage per user using iptables extension function, quota and time.

for example, I would like to set like this.

one can use 10M http traffic per hour per one IP address at business time(09h~18h).

Is it possible to set using iptables?

thanks in advance.

_________________________________________________________________
세계 어느 곳을 가더라도 친구가 있다니… 전 세계 친구들과의 즐거운 만남을 이 곳에서... http://personals.msn.co.kr/smt/msnkorea/smt.cfm?pg=home&emtrap=yes

#1 lore raw

Hello,

Quoted 8 lines · SB CH

Hello all.
I would like to limit the traffic usage per user
using iptables extension function, quota and time.
for example, I would like to set like this.
one can use 10M http traffic per hour per one IP address at business time(09h~18h).
Is it possible to set using iptables?
thanks in advance.

The problem with the current iptables framework is that you cannot "auto-remove" rules dynamically. For example, the quota match will increase the used-up quota, until the limit is reached, after which the rule will stop matching. However the quota rule will not go away by itself, and cannot be made so. So as things are right now, no, you cannot do what you want.

It would be easy enough however to modify the source of the quota match to implement quota per hour with a quota that would reset once the new time slice starts.

Have a nice day,

Fabrice.
--
Fabrice MARIE
Senior R&D Engineer
Celestix Networks
http://www.celestix.com/

"Silly hacker, root is for administrators"
-Unknown

#2 lore raw
In reply to SB CH

Hello SB,

It is only example don't use it in real setup !!!!!!! Add your additional rules for filtering !!!!!!!!!!!!!

Creat chain for every user (for optimal setup)
iptables -N user1
iptables -N user2
.........
# For user1
iptables -A user1 -m time --timestart 08:00 --timestop 09:00 --days \
Mon,Tue,Wed,Thu,Fri -m quota --quota 10485760 -j ACCEPT iptables -A user1 -m time --timestart 09:00 --timestop 10:00 --days \
Mon,Tue,Wed,Thu,Fri -m quota --quota 10485760 -j ACCEPT
.........
iptables -A user1 -m time --timestart 16:00 --timestop 17:00 --days \
Mon,Tue,Wed,Thu,Fri -m quota --quota 10485760 -j ACCEPT

# For user2
iptables -A user2 -m time --timestart 08:00 --timestop 09:00 --days \
Mon,Tue,Wed,Thu,Fri -m quota --quota 10485760 -j ACCEPT iptables -A user2 -m time --timestart 09:00 --timestop 10:00 --days \
Mon,Tue,Wed,Thu,Fri -m quota --quota 10485760 -j ACCEPT
.........
iptables -A user2 -m time --timestart 16:00 --timestop 17:00 --days \
Mon,Tue,Wed,Thu,Fri -m quota --quota 10485760 -j ACCEPT
.........

Send packets from users to his chain
# FORWARD

# For download limit
iptables -A FORWARD -i $IF1 -d $USER1_IP -j user1
iptables -A FORWARD -i $IF1 -d $USER2_IP -j user2
.........

# For upload limit
iptables -A FORWARD -i $IF1 -s $USER1_IP -j user1
iptables -A FORWARD -i $IF1 -s $USER2_IP -j user2
.........

# You can limit only upload or only download F.E. if you wish. # Sorry for my pure English :((

-----------------------------------
mailto:[email protected]
BR
Alexey Talikov
FORTEK
-----------------------------------

#3 lore raw
Quoted 12 lines · Alexey Talikov

Hello SB,
It is only example don't use it in real setup !!!!!!!
Add your additional rules for filtering !!!!!!!!!!!!! [...]
iptables -A user2 -m time --timestart 08:00 --timestop 09:00 --days \
Mon,Tue,Wed,Thu,Fri -m quota --quota 10485760 -j ACCEPT iptables -A user2 -m time --timestart 09:00 --timestop 10:00 --days \
Mon,Tue,Wed,Thu,Fri -m quota --quota 10485760 -j ACCEPT
.........
iptables -A user2 -m time --timestart 16:00 --timestop 17:00 --days \
Mon,Tue,Wed,Thu,Fri -m quota --quota 10485760 -j ACCEPT
.........

Quoted 8 lines

# You can limit only upload or only download F.E. if you wish. # Sorry for my pure English :((
-----------------------------------
mailto:[email protected]
BR
Alexey Talikov
FORTEK
-----------------------------------

Hello Alexey,

Well, yes, it would work :) But it means every day you would have to remove & re-add your rules, because when the quota is reached, it won't be reseted the next day automatically. Besides a quota per hour/sec or min match (modification of the quota match) would be a lot more elegant don't you think ? It's impressive to see what people can come up with when you give them a hammer ;-)

Have a nice day,

Fabrice.
--
Fabrice MARIE
Senior R&D Engineer
Celestix Networks
http://www.celestix.com/

"Silly hacker, root is for administrators"
-Unknown