<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>zedomax.com &#187; root classes</title>
	<atom:link href="http://zedomax.com/blog/tag/root-classes/feed/" rel="self" type="application/rss+xml" />
	<link>http://zedomax.com/blog</link>
	<description>Zedomax - The DIY, HOWTO, Mod, Hacks, Gadgets, and Tech Blog!</description>
	<lastBuildDate>Fri, 19 Mar 2010 21:00:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Linux Server Hack &#8211; How to Limit Bandwidth with Linux, TC, and iproute2!</title>
		<link>http://zedomax.com/blog/2008/09/25/linux-server-hack-how-to-limit-bandwidth-with-linux-tc-and-iproute2/</link>
		<comments>http://zedomax.com/blog/2008/09/25/linux-server-hack-how-to-limit-bandwidth-with-linux-tc-and-iproute2/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 03:40:28 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[Educational]]></category>
		<category><![CDATA[Featured Hacks]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[ceil]]></category>
		<category><![CDATA[cool script]]></category>
		<category><![CDATA[download speed]]></category>
		<category><![CDATA[high priority]]></category>
		<category><![CDATA[iface]]></category>
		<category><![CDATA[internal interface]]></category>
		<category><![CDATA[link speed]]></category>
		<category><![CDATA[load balancing]]></category>
		<category><![CDATA[medium priority]]></category>
		<category><![CDATA[priority class]]></category>
		<category><![CDATA[priority traffic]]></category>
		<category><![CDATA[root classes]]></category>
		<category><![CDATA[speed limit]]></category>
		<category><![CDATA[tc units]]></category>
		<category><![CDATA[traffic class]]></category>
		<category><![CDATA[upload speed]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://zedomax.com/blog/?p=9731</guid>
		<description><![CDATA[
Remember I did a quick post on how to write a load-balancing script (or bandwidth throttling)?
Well, today I found another cool script for limiting bandwidth.  I believe this one if more complicated but if you need it, it might be greatly helpful.
Here&#8217;s the code via Adamsinfo.com:

# Set some variables
#!/bin/bash
EXT_IFACE=”eth0″
INT_IFACE=”eth1″
TC=”tc”
UNITS=”kbit”
LINE=”10000″ #maximum ext link speed
LIMIT=”5000″ #maximum that [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="size-full wp-image-9732 aligncenter" title="code" src="http://zedomax.com/blog/wp-content/uploads/2008/09/code.jpg" alt="" width="263" height="261" /></p>
<p>Remember I did a quick post on <a href="http://zedomax.com/blog/2008/09/23/linux-web-server-hack-how-to-write-automated-load-balancing-script/" >how to write a load-balancing script (or bandwidth throttling)</a>?</p>
<p>Well, today I found another cool script for limiting bandwidth.  I believe this one if more complicated but if you need it, it might be greatly helpful.</p>
<p>Here&#8217;s the code via <a target="_blank" href="http://www.adamsinfo.com/bandwith-limiting-with-linux-tc-and-iproute2/" >Adamsinfo.com</a>:</p>
<p><code><br />
# Set some variables<br />
#!/bin/bash<br />
EXT_IFACE=”eth0″<br />
INT_IFACE=”eth1″<br />
TC=”tc”<br />
UNITS=”kbit”<br />
LINE=”10000″ #maximum ext link speed<br />
LIMIT=”5000″ #maximum that we’ll allow</code></p>
<p><span id="more-9731"></span><br />
# Set some variables for individual “classes” that we’ll use to shape internal upload speed, i.e. shaping eth0<br />
CLS1_RATE=”200″         # High Priority traffic class has 200kbit<br />
CLS2_RATE=”300″         # Medium Priority class has 300kbit<br />
CLS3_RATE=”4500″        # Bulk class has 4500kbit<br />
# (We’ll set which ones can borrow from which later)</p>
<p># Set some variables for individual “classes” that we’ll use to shape internal download speed, i.e. shaping eth1<br />
INT_CLS1_RATE=”1000″ #Priority<br />
INT_CLS2_RATE=”4000″ #Bulk</p>
<p># Delete current qdiscs. i.e. clean up<br />
${TC} qdisc del dev ${INT_IFACE} root<br />
${TC} qdisc del dev ${EXT_IFACE} root</p>
<p># Attach root qdiscs. We are using HTB here, and attaching this qdisc to both interfaces. We’ll label it “1:0″<br />
${TC} qdisc add dev ${INT_IFACE} root handle 1:0 htb<br />
${TC} qdisc add dev ${EXT_IFACE} root handle 1:0 htb</p>
<p># Create root classes, with the maximum limits defined<br />
# One for eth1<br />
${TC} class add dev ${INT_IFACE} parent 1:0 classid 1:1 htb rate ${LIMIT}${UNITS} ceil ${LIMIT}${UNITS}<br />
# One for eth0<br />
${TC} class add dev ${EXT_IFACE} parent 1:0 classid 1:1 htb rate ${LIMIT}${UNITS} ceil ${LIMIT}${UNITS}</p>
<p># Create child classes<br />
# These are for our internal interface eth1<br />
# Create a class labelled “1:2″ and give it the limit defined above<br />
${TC} class add dev ${INT_IFACE} parent 1:1 classid 1:2 htb rate ${INT_CLS1_RATE}${UNITS} ceil ${LIMIT}${UNITS}<br />
# Create a class labelled “1:3″ and give it the limit defined above<br />
${TC} class add dev ${INT_IFACE} parent 1:1 classid 1:3 htb rate ${INT_CLS2_RATE}${UNITS} ceil ${INT_CLS2_RATE}${UNITS}</p>
<p># EXT_IF (upload) now. We also set which classes can borrow and lend.<br />
# This class is guaranteed 200kbit and can burst up to 5000kbit if available<br />
${TC} class add dev ${EXT_IFACE} parent 1:1 classid 1:2 htb rate ${CLS1_RATE}${UNITS} ceil ${LIMIT}${UNITS}<br />
# This class is guaranteed 300kbit and can burst up to 5000kbit-200kbit=4800kbit if available<br />
${TC} class add dev ${EXT_IFACE} parent 1:1 classid 1:3 htb rate ${CLS2_RATE}${UNITS} ceil `echo ${LIMIT}-${CLS1_RATE}|bc`${UNITS}<br />
# This class can is guaranteed 4500kbit and can’t burst past it (5000kbit-200kbit-300kbit=4500kbit).<br />
# I.e. even if our bulk traffic goes crazy, the two classes above are still guaranteed availability.<br />
${TC} class add dev ${EXT_IFACE} parent 1:1 classid 1:4 htb rate ${CLS3_RATE}${UNITS} ceil `echo ${LIMIT}-${CLS1_RATE}-${CLS2_RATE}|bc`${UNITS}</p>
<p># Add pfifo. Read more about pfifo elsewhere, it’s outside the scope of this howto.<br />
${TC} qdisc add dev ${INT_IFACE} parent 1:2 handle 12: pfifo limit 10<br />
${TC} qdisc add dev ${INT_IFACE} parent 1:3 handle 13: pfifo limit 10<br />
${TC} qdisc add dev ${EXT_IFACE} parent 1:2 handle 12: pfifo limit 10<br />
${TC} qdisc add dev ${EXT_IFACE} parent 1:3 handle 13: pfifo limit 10<br />
${TC} qdisc add dev ${EXT_IFACE} parent 1:4 handle 14: pfifo limit 10</p>
<p>### Done adding all the classes, now set up some rules! ###<br />
# INT_IFACE<br />
# Note the ‘dst’ direction. Traffic that goes OUT of our internal interface and to our servers is out server’s download speed, so SOME_IMPORTANT_IP is allocated to 1:2 class for download.<br />
${TC} filter add dev ${INT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip dst SOME_IMPORTANT_IP/32 flowid 1:2<br />
${TC} filter add dev ${INT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip dst SOME_OTHER_IMPORTANT_IP/32 flowid 1:2<br />
#All other servers download speed goes to 1:3 &#8211; not as important as the above two<br />
${TC} filter add dev ${INT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip dst 0.0.0.0/0 flowid 1:3</p>
<p># EXT_IFACE<br />
# Prioritize DNS requests<br />
${TC} filter add dev ${EXT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip src IMPORTANT_IP/32 match ip sport 53 0xffff flowid 1:2<br />
# SSH is important<br />
${TC} filter add dev ${EXT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip src IMPORTANT_IP/32 match ip sport 22 0xffff flowid 1:2<br />
# Our exim SMTP server is important too<br />
${TC} filter add dev ${EXT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip src 217.10.156.197/32 match ip sport 25 0xffff flowid 1:3<br />
# The bulk<br />
${TC} filter add dev ${EXT_IFACE} parent 1:0 protocol ip prio 1 u32 match ip src 0.0.0.0/0 flowid 1:4</p>
<p>Brought to you by: <a href="http://zedomax.com/blog" >Zedomax.com</a></p>
<p><a href="http://zedomax.com/blog/2008/09/25/linux-server-hack-how-to-limit-bandwidth-with-linux-tc-and-iproute2/" >Linux Server Hack &#8211; How to Limit Bandwidth with Linux, TC, and iproute2!</a></p>

	<span style="display:none"><a href="http://zedomax.com/blog/tag/ceil/" title="ceil" rel="tag">ceil</a>, <a href="http://zedomax.com/blog/category/computer/" title="Computer" rel="tag">Computer</a>, <a href="http://zedomax.com/blog/tag/cool-script/" title="cool script" rel="tag">cool script</a>, <a href="http://zedomax.com/blog/category/diy/" title="DIY" rel="tag">DIY</a>, <a href="http://zedomax.com/blog/tag/download-speed/" title="download speed" rel="tag">download speed</a>, <a href="http://zedomax.com/blog/category/technology/educational/" title="Educational" rel="tag">Educational</a>, <a href="http://zedomax.com/blog/category/featured/featured-hacks/" title="Featured Hacks" rel="tag">Featured Hacks</a>, <a href="http://zedomax.com/blog/category/diy/hack/" title="Hack" rel="tag">Hack</a>, <a href="http://zedomax.com/blog/tag/high-priority/" title="high priority" rel="tag">high priority</a>, <a href="http://zedomax.com/blog/category/diy/howto/" title="HOWTO" rel="tag">HOWTO</a>, <a href="http://zedomax.com/blog/tag/iface/" title="iface" rel="tag">iface</a>, <a href="http://zedomax.com/blog/tag/internal-interface/" title="internal interface" rel="tag">internal interface</a>, <a href="http://zedomax.com/blog/tag/link-speed/" title="link speed" rel="tag">link speed</a>, <a href="http://zedomax.com/blog/category/computer/linux-technology/" title="Linux" rel="tag">Linux</a>, <a href="http://zedomax.com/blog/tag/load-balancing/" title="load balancing" rel="tag">load balancing</a>, <a href="http://zedomax.com/blog/tag/medium-priority/" title="medium priority" rel="tag">medium priority</a>, <a href="http://zedomax.com/blog/category/misc/" title="Misc" rel="tag">Misc</a>, <a href="http://zedomax.com/blog/tag/priority-class/" title="priority class" rel="tag">priority class</a>, <a href="http://zedomax.com/blog/tag/priority-traffic/" title="priority traffic" rel="tag">priority traffic</a>, <a href="http://zedomax.com/blog/tag/root-classes/" title="root classes" rel="tag">root classes</a>, <a href="http://zedomax.com/blog/tag/speed-limit/" title="speed limit" rel="tag">speed limit</a>, <a href="http://zedomax.com/blog/tag/tc-units/" title="tc units" rel="tag">tc units</a>, <a href="http://zedomax.com/blog/tag/traffic-class/" title="traffic class" rel="tag">traffic class</a>, <a href="http://zedomax.com/blog/category/computer/linux-technology/ubuntu/" title="Ubuntu" rel="tag">Ubuntu</a>, <a href="http://zedomax.com/blog/tag/upload-speed/" title="upload speed" rel="tag">upload speed</a>, <a href="http://zedomax.com/blog/tag/variables/" title="variables" rel="tag">variables</a>, <a href="http://zedomax.com/blog/category/technology/web-technology/" title="Web" rel="tag">Web</a></span>

	<h3>Related posts</h3>
	<ul class="st-related-posts">
	<li><a href="http://zedomax.com/blog/2009/03/25/web-diy-how-to-setup-load-balancing-linux-web-servers/" title="Web DIY &#8211; How to Setup Load Balancing Linux Web Servers! (March 25, 2009)">Web DIY &#8211; How to Setup Load Balancing Linux Web Servers!</a> </li>
	<li><a href="http://zedomax.com/blog/2008/09/29/ubuntu-hack-how-to-make-ubuntu-run-super-fast/" title="Ubuntu Hack &#8211; How to Make Ubuntu run Super Fast! (September 29, 2008)">Ubuntu Hack &#8211; How to Make Ubuntu run Super Fast!</a> </li>
	<li><a href="http://zedomax.com/blog/2008/05/06/passenger-moons-speeding-camera/" title="Passenger &#8220;moons&#8221; Speeding Camera (May 6, 2008)">Passenger &#8220;moons&#8221; Speeding Camera</a> </li>
	<li><a href="http://zedomax.com/blog/2008/07/28/linux-server-hack-how-to-setup-a-shell-script-to-auto-restart-apache-httpd-server/" title="Linux Server Hack &#8211; How to setup a Shell Script to Auto Restart Apache Httpd Server! (July 28, 2008)">Linux Server Hack &#8211; How to setup a Shell Script to Auto Restart Apache Httpd Server!</a> </li>
	<li><a href="http://zedomax.com/blog/2008/10/06/fords-key-with-a-chip-prevents-teenagers-from-driving-over-80mph-and-more-parental-control/" title="Ford&#8217;s Key with a Chip prevents Teenagers from driving over 80MPH and more Parental Control! (October 6, 2008)">Ford&#8217;s Key with a Chip prevents Teenagers from driving over 80MPH and more Parental Control!</a> </li>
	<li><a href="http://zedomax.com/blog/2008/05/28/digital-plant-tells-you-their-feelings/" title="Digital Plant tells you their feelings! (May 28, 2008)">Digital Plant tells you their feelings!</a> </li>
	<li><a href="http://zedomax.com/blog/2008/07/16/chocolate-is-it-bad-for-dogs/" title="Chocolate, Is it Bad for Dogs? (July 16, 2008)">Chocolate, Is it Bad for Dogs?</a> </li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://zedomax.com/blog/2008/09/25/linux-server-hack-how-to-limit-bandwidth-with-linux-tc-and-iproute2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
