Hello, I need to setup HTB to limit the bandwidth, but I need to have 2 types of limits, because my ISP gives me more bandwith for sites located in my country, than others located outside. I have setup the following script in which I mark packets with mark 6 for the ip clasess for the sites in my country. What I don''t know is how to continue the script with assigning lower limits to everything else not going from ip''s in --set-mark 6. Maybe some of can enlighten me about this. Thanks, Alex #!/bin/sh #Mark metro packets /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 213.154.152.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 213.154.119.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 213.154.117.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 213.154.118.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 213.154.116.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 213.154.126.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 213.157.176.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 213.157.117.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 213.157.126.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 80.97.173.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 82.137.58.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 82.137.56.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 81.196.96.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 81.196.97.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 62.231.74.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 213.157.176.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 192.226.30.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 193.231.7.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 192.129.4.0/24 -j MARK --set-mark 6 /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 193.231.15.0/24 -j MARK --set-mark 6 #end metro # #2. Anything else /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 0/0 -j MARK --set-mark 5 /sbin/tc qdisc del dev eth2 root echo "Deleted old root disk on eth2" /sbin/tc qdisc add dev eth2 root handle 1: htb default 10 /sbin/tc class add dev eth2 parent 1: classid 1:1 htb rate 10M #metro /sbin/tc class add dev eth2 parent 1:1 classid 1:10 htb rate 10M /sbin/tc filter add dev eth2 protocol ip parent 1:10 prio 3 handle 6 flowid 1:10 #international /sbin/tc class add dev eth2 parent 1:1 classid 1:2 htb rate 10M /sbin/tc filter add dev eth2 protocol ip parent 1:10 prio 3 handle 5 flowid 1:2 /sbin/tc class add dev eth2 parent 1:1 classid 1:11 htb rate 50kbit ceil 100kbit prio 5 /sbin/tc filter add dev eth2 parent 1:0 protocol ip prio 5 u32 match ip dst 192.168.254.10 flowid 1:11 /sbin/tc class add dev eth2 parent 1:1 classid 1:12 htb rate 50kbit ceil 100kbit prio 5 /sbin/tc filter add dev eth2 parent 1:0 protocol ip prio 5 u32 match ip dst 192.168.254.11 flowid 1:12 /sbin/tc class add dev eth2 parent 1:1 classid 1:13 htb rate 50kbit ceil 100kbit prio 5 /sbin/tc filter add dev eth2 parent 1:0 protocol ip prio 5 u32 match ip dst 192.168.254.12 flowid 1:13 /sbin/tc class add dev eth2 parent 1:1 classid 1:14 htb rate 50kbit ceil 100kbit prio 5 /sbin/tc filter add dev eth2 parent 1:0 protocol ip prio 5 u32 match ip dst 192.168.254.13 flowid 1:14 .... etc _______________________________________________ LARTC mailing list / LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/
Thanks for your replay, it really helps, but to take the question further, from what you have seen in my sample script, how should I classify packets with "tc" ? I don''t know how to put them in separate classes,. What I have in my script will only shape metro traffic, but for international how would the "tc" command be? Something like: /sbin/tc class add dev eth2 parent 1:2 classid 2:11 htb rate 50kbit ceil 100kbit prio 5 /sbin/tc filter add dev eth2 parent 1:0 protocol ip prio 5 u32 match ip dst 192.168.254.10 flowid 1:11 Would this be the correct commands? Thanks again. Alex ---begin my script---- sbin/tc qdisc add dev eth2 root handle 1: htb default 10 /sbin/tc class add dev eth2 parent 1: classid 1:1 htb rate 10M #metro /sbin/tc class add dev eth2 parent 1:1 classid 1:10 htb rate 10M /sbin/tc filter add dev eth2 protocol ip parent 1:10 prio 3 handle 6 flowid 1:10 #international /sbin/tc class add dev eth2 parent 1:1 classid 1:2 htb rate 10M /sbin/tc filter add dev eth2 protocol ip parent 1:10 prio 3 handle 5 flowid 1:2 /sbin/tc class add dev eth2 parent 1:1 classid 1:11 htb rate 50kbit ceil 100kbit prio 5 /sbin/tc filter add dev eth2 parent 1:0 protocol ip prio 5 u32 match ip dst 192.168.254.10 flowid 1:11 /sbin/tc class add dev eth2 parent 1:1 classid 1:12 htb rate 50kbit ceil 100kbit prio 5 /sbin/tc filter add dev eth2 parent 1:0 protocol ip prio 5 u32 match ip dst 192.168.254.11 flowid 1:12 ....etc --end-- ----- Original Message ----- From: <cmulcahy@avesi.com> To: "Alex" <alex@hostingcenter.ro> Sent: Tuesday, September 30, 2003 9:07 PM Subject: Re: HTB and metro+int. limits> Alex > > Alex writes: > > > Hello, > > I need to setup HTB to limit the bandwidth, but I need to have 2 typesof> > limits, because my ISP gives me more bandwith for sites located in my > > country, than others located outside. I have setup the following scriptin> > which I mark packets with mark 6 for the ip clasess for the sites in my > > country. What I don''t know is how to continue the script with assigning > > lower limits to everything else not going from ip''s in --set-mark 6. > > Maybe some of can enlighten me about this. > > Thanks, > > > > Alex > > > <snip> > ...... > > /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 193.231.15.0/24 -j > > MARK --set-mark 6 > > #end metro > > # > > #2. Anything else > > /sbin/iptables -t mangle -A PREROUTING -i eth2 -d 0/0 -j MARK --set-mark5> > </snip> > > This will not differentiate your traffic. Everything "-i eth2" will endup> marked ''5'' because iptables will evaluate against every rule in order, > eventually marking them ''5'' whether they have previously been marked ''6''or> not. > > You need to create a new table with two commands for each address range. > ie: > > /sbin/iptables -t mangle -N MYMARKER > /sbin/iptables -t mangle -A PREROUTING -i eth2 -j MYMARKER > > # and ... > /sbin/iptables -t mangle -A MYMARKER -d 193.231.15.0/24 -j MARK --set-mark6> /sbin/iptables -t mangle -A MYMARKER -d 193.231.15.0/24 -j RETURN > # for each metro range, and finally .... > /sbin/iptables -t mangle -A MYMARKER -j MARK --set-mark 5 > /sbin/iptables -t mangle -A MYMARKER -j RETURN > > The separate table and the ''RETURN'' statements give you the"short-circuit"> evaluation you require. > > BTW: You might be able to consolidate your metro class-C''s into fewer > (larger) CIDR ranges to speed evaluation. ( Your upstream provider has > likely been allocated them in this manner ) > > mulc >_______________________________________________ LARTC mailing list / LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/
On Tuesday 30 September 2003 21:27, Alex wrote:> Thanks for your replay, it really helps, but to take the question further, > from what you have seen in my sample script, how should I classify packets > with "tc" ? I don''t know how to put them in separate classes,. What I have > in my script will only shape metro traffic, but for international how would > the "tc" command be? > Something like: > /sbin/tc class add dev eth2 parent 1:2 classid 2:11 htb rate 50kbit ceil > 100kbit prio 5 > /sbin/tc filter add dev eth2 parent 1:0 protocol ip prio 5 u32 match ip dst > 192.168.254.10 flowid 1:11 > Would this be the correct commands?No. You create a class with a wrong number. If the parent class is 1:x, the class name has to be 1:y.> Thanks again. > > Alex > ---begin my script---- > sbin/tc qdisc add dev eth2 root handle 1: htb default 10 > /sbin/tc class add dev eth2 parent 1: classid 1:1 htb rate 10M > #metro > /sbin/tc class add dev eth2 parent 1:1 classid 1:10 htb rate 10M > /sbin/tc filter add dev eth2 protocol ip parent 1:10 prio 3 handle 6 flowid > 1:10This filter will not do much (typo?). You attach it to class 1:10 (the parent parameter). This should be 1: so all packets leaving eth2 will be checked against this filter. And is 10M working? Normally 10mbit is used. Stef -- stef.coene@docum.org "Using Linux as bandwidth manager" http://www.docum.org/ #lartc @ irc.openprojects.net _______________________________________________ LARTC mailing list / LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/
I''m sorry, but I''m still confused about assigning separate limits for metro and international traffic. After I mark metro traffic with --set-mark 6 and int. traffic with --set-mark 5 what''s the next step? Can someone give me an example? It seems that my approach is somehow wrong after marking of the packets. Thanks again. Alex ----- Original Message ----- From: "Stef Coene" <stef.coene@docum.org> To: "Alex" <alex@hostingcenter.ro>; "Lartc" <lartc@mailman.ds9a.nl>; <cmulcahy@avesi.com> Sent: Wednesday, October 01, 2003 12:59 PM Subject: Re: [LARTC] Re: HTB and metro+int. limits> On Tuesday 30 September 2003 21:27, Alex wrote: > > Thanks for your replay, it really helps, but to take the questionfurther,> > from what you have seen in my sample script, how should I classifypackets> > with "tc" ? I don''t know how to put them in separate classes,. What Ihave> > in my script will only shape metro traffic, but for international howwould> > the "tc" command be? > > Something like: > > /sbin/tc class add dev eth2 parent 1:2 classid 2:11 htb rate 50kbit ceil > > 100kbit prio 5 > > /sbin/tc filter add dev eth2 parent 1:0 protocol ip prio 5 u32 match ipdst> > 192.168.254.10 flowid 1:11 > > Would this be the correct commands? > No. You create a class with a wrong number. If the parent class is 1:x,the> class name has to be 1:y. > > > Thanks again. > > > > Alex > > ---begin my script---- > > sbin/tc qdisc add dev eth2 root handle 1: htb default 10 > > /sbin/tc class add dev eth2 parent 1: classid 1:1 htb rate 10M > > #metro > > /sbin/tc class add dev eth2 parent 1:1 classid 1:10 htb rate 10M > > /sbin/tc filter add dev eth2 protocol ip parent 1:10 prio 3 handle 6flowid> > 1:10 > This filter will not do much (typo?). You attach it to class 1:10 (theparent> parameter). This should be 1: so all packets leaving eth2 will be checked > against this filter. > And is 10M working? Normally 10mbit is used. > > Stef > > -- > stef.coene@docum.org > "Using Linux as bandwidth manager" > http://www.docum.org/ > #lartc @ irc.openprojects.net > > _______________________________________________ > LARTC mailing list / LARTC@mailman.ds9a.nl > http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/_______________________________________________ LARTC mailing list / LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/
I forgot to say that I have put my script on http://retea.hostingcenter.ro/htb.txt Maybe someone could lead to to the correct sintax if there''s something wrong. Alex ----- Original Message ----- From: "Stef Coene" <stef.coene@docum.org> To: "Alex" <alex@hostingcenter.ro>; "Lartc" <lartc@mailman.ds9a.nl>; <cmulcahy@avesi.com> Sent: Wednesday, October 01, 2003 12:59 PM Subject: Re: [LARTC] Re: HTB and metro+int. limits> On Tuesday 30 September 2003 21:27, Alex wrote: > > Thanks for your replay, it really helps, but to take the questionfurther,> > from what you have seen in my sample script, how should I classifypackets> > with "tc" ? I don''t know how to put them in separate classes,. What Ihave> > in my script will only shape metro traffic, but for international howwould> > the "tc" command be? > > Something like: > > /sbin/tc class add dev eth2 parent 1:2 classid 2:11 htb rate 50kbit ceil > > 100kbit prio 5 > > /sbin/tc filter add dev eth2 parent 1:0 protocol ip prio 5 u32 match ipdst> > 192.168.254.10 flowid 1:11 > > Would this be the correct commands? > No. You create a class with a wrong number. If the parent class is 1:x,the> class name has to be 1:y. > > > Thanks again. > > > > Alex > > ---begin my script---- > > sbin/tc qdisc add dev eth2 root handle 1: htb default 10 > > /sbin/tc class add dev eth2 parent 1: classid 1:1 htb rate 10M > > #metro > > /sbin/tc class add dev eth2 parent 1:1 classid 1:10 htb rate 10M > > /sbin/tc filter add dev eth2 protocol ip parent 1:10 prio 3 handle 6flowid> > 1:10 > This filter will not do much (typo?). You attach it to class 1:10 (theparent> parameter). This should be 1: so all packets leaving eth2 will be checked > against this filter. > And is 10M working? Normally 10mbit is used. > > Stef > > -- > stef.coene@docum.org > "Using Linux as bandwidth manager" > http://www.docum.org/ > #lartc @ irc.openprojects.net > > _______________________________________________ > LARTC mailing list / LARTC@mailman.ds9a.nl > http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/_______________________________________________ LARTC mailing list / LARTC@mailman.ds9a.nl http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/