<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=BillW</id>
	<title>OpenVZ Virtuozzo Containers Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=BillW"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/BillW"/>
	<updated>2026-05-15T18:53:52Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Traffic_shaping_with_tc&amp;diff=3163</id>
		<title>Traffic shaping with tc</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Traffic_shaping_with_tc&amp;diff=3163"/>
		<updated>2007-06-05T13:37:14Z</updated>

		<summary type="html">&lt;p&gt;BillW: /* An alternate approch using HTB */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Sometimes it's necessary to limit traffic bandwidth from and to a [[VE]].&lt;br /&gt;
You can do it using ordinary &amp;lt;code&amp;gt;tc&amp;lt;/code&amp;gt; tool.&lt;br /&gt;
&lt;br /&gt;
== Packet routes ==&lt;br /&gt;
First of all, a few words about how packets travel from and to a [[VE]].&lt;br /&gt;
Suppose we have [[Hardware Node]] (HN) with a VE on it, and this VE talks&lt;br /&gt;
to some Remote Host (RH). HN has one &amp;quot;real&amp;quot; network interface &amp;lt;tt&amp;gt;eth0&amp;lt;/tt&amp;gt; and, &lt;br /&gt;
thanks to OpenVZ, there is also &amp;quot;virtual&amp;quot; network interface &amp;lt;tt&amp;gt;venet0&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Inside the VE we have interface &amp;lt;tt&amp;gt;venet0:0&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    venet0:0               venet0    eth0&lt;br /&gt;
VE &amp;gt;-------------&amp;gt;-------------&amp;gt; HN &amp;gt;---------&amp;gt;--------&amp;gt; RH&lt;br /&gt;
&lt;br /&gt;
    venet0:0               venet0    eth0&lt;br /&gt;
VE &amp;lt;-------------&amp;lt;-------------&amp;lt; HN &amp;lt;---------&amp;lt;--------&amp;lt; RH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Limiting outgoing bandwidth ==&lt;br /&gt;
We can limit VE outgoing bandwidth by setting the &amp;lt;tt&amp;gt;tc&amp;lt;/tt&amp;gt; filter on &amp;lt;tt&amp;gt;eth0&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEV=eth0&lt;br /&gt;
tc qdisc del dev $DEV root&lt;br /&gt;
tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 100mbit&lt;br /&gt;
tc class add dev $DEV parent 1: classid 1:1 cbq rate 256kbit allot 1500 prio 5 bounded isolated&lt;br /&gt;
tc filter add dev $DEV parent 1: protocol ip prio 16 u32 match ip src X.X.X.X flowid 1:1&lt;br /&gt;
tc qdisc add dev $DEV parent 1:1 sfq perturb 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
X.X.X.X is an IP address of VE.&lt;br /&gt;
&lt;br /&gt;
== Limiting incoming bandwidth ==&lt;br /&gt;
This can be done by setting the &amp;lt;code&amp;gt;tc&amp;lt;/code&amp;gt; filter on &amp;lt;code&amp;gt;venet0&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEV=venet0&lt;br /&gt;
tc qdisc del dev $DEV root&lt;br /&gt;
tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 100mbit&lt;br /&gt;
tc class add dev $DEV parent 1: classid 1:1 cbq rate 256kbit allot 1500 prio 5 bounded isolated&lt;br /&gt;
tc filter add dev $DEV parent 1: protocol ip prio 16 u32 match ip dst X.X.X.X flowid 1:1&lt;br /&gt;
tc qdisc add dev $DEV parent 1:1 sfq perturb 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note that &amp;lt;code&amp;gt;X.X.X.X&amp;lt;/code&amp;gt; is an IP address of VE.&lt;br /&gt;
&lt;br /&gt;
== Limiting VE to HN talks ==&lt;br /&gt;
As you can see, two filters above don't limit [[VE]] to [[HN]] talks.&lt;br /&gt;
I mean a [[VE]] can emit as much traffic as it wishes. To make such a limitation from the [[HN]],&lt;br /&gt;
it is necessary to use &amp;lt;tt&amp;gt;tc&amp;lt;/tt&amp;gt; police on &amp;lt;tt&amp;gt;venet0&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEV=venet0&lt;br /&gt;
tc filter add dev $DEV parent 1: protocol ip prio 20 u32 match u32 1 0x0000 police rate 2kbit buffer 10k drop flowid :1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Limiting packets per second rate from VE ==&lt;br /&gt;
To prevent dos atacks from the VE you can limit packets per second rate using iptables.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEV=eth0&lt;br /&gt;
iptables -I FORWARD 1 -o $DEV -s X.X.X.X -m limit --limit 200/sec -j ACCEPT&lt;br /&gt;
iptables -I FORWARD 2 -o $DEV -s X.X.X.X -j DROP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here &amp;lt;code&amp;gt;X.X.X.X&amp;lt;/code&amp;gt; is an IP address of VE&lt;br /&gt;
&lt;br /&gt;
== An alternate approch using HTB ==&lt;br /&gt;
&lt;br /&gt;
For details refer to the [http://luxik.cdi.cz/~devik/qos/htb/ HTB Home Page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# Incoming traffic control&lt;br /&gt;
#&lt;br /&gt;
VE_IP1=$1&lt;br /&gt;
VE_IP2=$2&lt;br /&gt;
DEV=venet0&lt;br /&gt;
#&lt;br /&gt;
tc qdisc del dev $DEV root&lt;br /&gt;
#&lt;br /&gt;
tc qdisc add dev $DEV root handle 1: htb default 10&lt;br /&gt;
#&lt;br /&gt;
tc class add dev $DEV parent 1: classid 1:1 htb rate 100mbit burst 15k&lt;br /&gt;
tc class add dev $DEV parent 1:1 classid 1:10 htb rate 10mbit ceil 10mbit burst 15k&lt;br /&gt;
tc class add dev $DEV parent 1:1 classid 1:20 htb rate 20mbit ceil 20mbit burst 15k&lt;br /&gt;
tc class add dev $DEV parent 1:1 classid 1:30 htb rate 30mbit ceil 30mbit burst 15k&lt;br /&gt;
#&lt;br /&gt;
tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10&lt;br /&gt;
tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10&lt;br /&gt;
tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10&lt;br /&gt;
#&lt;br /&gt;
if [ ! -z $VE_IP1 ]; then&lt;br /&gt;
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip dst &amp;quot;$VE_IP1&amp;quot; flowid 1:20 &lt;br /&gt;
fi&lt;br /&gt;
if [ ! -z $VE_IP2 ]; then&lt;br /&gt;
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip dst &amp;quot;$VE_IP2&amp;quot; flowid 1:30 &lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
echo;echo &amp;quot;tc configuration for $DEV:&amp;quot;&lt;br /&gt;
tc qdisc show dev $DEV&lt;br /&gt;
tc class show dev $DEV&lt;br /&gt;
tc filter show dev $DEV&lt;br /&gt;
#&lt;br /&gt;
# Outgoing traffic control&lt;br /&gt;
#&lt;br /&gt;
DEV=eth0&lt;br /&gt;
#&lt;br /&gt;
tc qdisc del dev $DEV root&lt;br /&gt;
#&lt;br /&gt;
tc qdisc add dev $DEV root handle 1: htb default 10&lt;br /&gt;
#&lt;br /&gt;
tc class add dev $DEV parent 1: classid 1:1 htb rate 100mbit burst 15k&lt;br /&gt;
tc class add dev $DEV parent 1:1 classid 1:10 htb rate 10mbit ceil 10mbit burst 15k&lt;br /&gt;
tc class add dev $DEV parent 1:1 classid 1:20 htb rate 20mbit ceil 20mbit burst 15k&lt;br /&gt;
tc class add dev $DEV parent 1:1 classid 1:30 htb rate 30mbit ceil 30mbit burst 15k&lt;br /&gt;
#&lt;br /&gt;
tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10&lt;br /&gt;
tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10&lt;br /&gt;
tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10&lt;br /&gt;
#&lt;br /&gt;
if [ ! -z $VE_IP1 ]; then&lt;br /&gt;
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip src &amp;quot;$VE_IP1&amp;quot; flowid 1:20&lt;br /&gt;
fi&lt;br /&gt;
if [ ! -z $VE_IP2 ]; then&lt;br /&gt;
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip src &amp;quot;$VE_IP2&amp;quot; flowid 1:30&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
echo;echo &amp;quot;tc configuration for $DEV:&amp;quot;&lt;br /&gt;
tc qdisc show dev $DEV&lt;br /&gt;
tc class show dev $DEV&lt;br /&gt;
tc filter show dev $DEV&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://lartc.org/howto/ Linux Advanced Routing &amp;amp; Traffic Control HOWTO]&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>BillW</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Traffic_shaping_with_tc&amp;diff=3159</id>
		<title>Traffic shaping with tc</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Traffic_shaping_with_tc&amp;diff=3159"/>
		<updated>2007-06-04T20:01:08Z</updated>

		<summary type="html">&lt;p&gt;BillW: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Sometimes it's necessary to limit traffic bandwidth from and to a [[VE]].&lt;br /&gt;
You can do it using ordinary &amp;lt;code&amp;gt;tc&amp;lt;/code&amp;gt; tool.&lt;br /&gt;
&lt;br /&gt;
== Packet routes ==&lt;br /&gt;
First of all, a few words about how packets travel from and to a [[VE]].&lt;br /&gt;
Suppose we have [[Hardware Node]] (HN) with a VE on it, and this VE talks&lt;br /&gt;
to some Remote Host (RH). HN has one &amp;quot;real&amp;quot; network interface &amp;lt;tt&amp;gt;eth0&amp;lt;/tt&amp;gt; and, &lt;br /&gt;
thanks to OpenVZ, there is also &amp;quot;virtual&amp;quot; network interface &amp;lt;tt&amp;gt;venet0&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Inside the VE we have interface &amp;lt;tt&amp;gt;venet0:0&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    venet0:0               venet0    eth0&lt;br /&gt;
VE &amp;gt;-------------&amp;gt;-------------&amp;gt; HN &amp;gt;---------&amp;gt;--------&amp;gt; RH&lt;br /&gt;
&lt;br /&gt;
    venet0:0               venet0    eth0&lt;br /&gt;
VE &amp;lt;-------------&amp;lt;-------------&amp;lt; HN &amp;lt;---------&amp;lt;--------&amp;lt; RH&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Limiting outgoing bandwidth ==&lt;br /&gt;
We can limit VE outgoing bandwidth by setting the &amp;lt;tt&amp;gt;tc&amp;lt;/tt&amp;gt; filter on &amp;lt;tt&amp;gt;eth0&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEV=eth0&lt;br /&gt;
tc qdisc del dev $DEV root&lt;br /&gt;
tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 100mbit&lt;br /&gt;
tc class add dev $DEV parent 1: classid 1:1 cbq rate 256kbit allot 1500 prio 5 bounded isolated&lt;br /&gt;
tc filter add dev $DEV parent 1: protocol ip prio 16 u32 match ip src X.X.X.X flowid 1:1&lt;br /&gt;
tc qdisc add dev $DEV parent 1:1 sfq perturb 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
X.X.X.X is an IP address of VE.&lt;br /&gt;
&lt;br /&gt;
== Limiting incoming bandwidth ==&lt;br /&gt;
This can be done by setting the &amp;lt;code&amp;gt;tc&amp;lt;/code&amp;gt; filter on &amp;lt;code&amp;gt;venet0&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEV=venet0&lt;br /&gt;
tc qdisc del dev $DEV root&lt;br /&gt;
tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 100mbit&lt;br /&gt;
tc class add dev $DEV parent 1: classid 1:1 cbq rate 256kbit allot 1500 prio 5 bounded isolated&lt;br /&gt;
tc filter add dev $DEV parent 1: protocol ip prio 16 u32 match ip dst X.X.X.X flowid 1:1&lt;br /&gt;
tc qdisc add dev $DEV parent 1:1 sfq perturb 10&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note that &amp;lt;code&amp;gt;X.X.X.X&amp;lt;/code&amp;gt; is an IP address of VE.&lt;br /&gt;
&lt;br /&gt;
== Limiting VE to HN talks ==&lt;br /&gt;
As you can see, two filters above don't limit [[VE]] to [[HN]] talks.&lt;br /&gt;
I mean a [[VE]] can emit as much traffic as it wishes. To make such a limitation from the [[HN]],&lt;br /&gt;
it is necessary to use &amp;lt;tt&amp;gt;tc&amp;lt;/tt&amp;gt; police on &amp;lt;tt&amp;gt;venet0&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEV=venet0&lt;br /&gt;
tc filter add dev $DEV parent 1: protocol ip prio 20 u32 match u32 1 0x0000 police rate 2kbit buffer 10k drop flowid :1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Limiting packets per second rate from VE ==&lt;br /&gt;
To prevent dos atacks from the VE you can limit packets per second rate using iptables.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEV=eth0&lt;br /&gt;
iptables -I FORWARD 1 -o $DEV -s X.X.X.X -m limit --limit 200/sec -j ACCEPT&lt;br /&gt;
iptables -I FORWARD 2 -o $DEV -s X.X.X.X -j DROP&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Here &amp;lt;code&amp;gt;X.X.X.X&amp;lt;/code&amp;gt; is an IP address of VE&lt;br /&gt;
&lt;br /&gt;
== An alternate approch using HTB ==&lt;br /&gt;
&lt;br /&gt;
For details refer to the [http://luxik.cdi.cz/~devik/qos/htb/ HTB Home Page]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
#&lt;br /&gt;
# Incominfg traffic control&lt;br /&gt;
#&lt;br /&gt;
VE_IP1=$1&lt;br /&gt;
VE_IP2=$2&lt;br /&gt;
DEV=venet0&lt;br /&gt;
#&lt;br /&gt;
tc qdisc del dev $DEV root&lt;br /&gt;
#&lt;br /&gt;
tc qdisc add dev $DEV root handle 1: htb default 10&lt;br /&gt;
#&lt;br /&gt;
tc class add dev $DEV parent 1: classid 1:1 htb rate 100mbit burst 15k&lt;br /&gt;
tc class add dev $DEV parent 1:1 classid 1:10 htb rate 10mbit ceil 10mbit burst 15k&lt;br /&gt;
tc class add dev $DEV parent 1:1 classid 1:20 htb rate 20mbit ceil 20mbit burst 15k&lt;br /&gt;
tc class add dev $DEV parent 1:1 classid 1:30 htb rate 30mbit ceil 30mbit burst 15k&lt;br /&gt;
#&lt;br /&gt;
tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10&lt;br /&gt;
tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10&lt;br /&gt;
tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10&lt;br /&gt;
#&lt;br /&gt;
if [ ! -z $VE_IP1 ]; then&lt;br /&gt;
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip dst &amp;quot;$VE_IP1&amp;quot; flowid 1:20 &lt;br /&gt;
fi&lt;br /&gt;
if [ ! -z $VE_IP2 ]; then&lt;br /&gt;
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip dst &amp;quot;$VE_IP2&amp;quot; flowid 1:30 &lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
echo;echo &amp;quot;tc configuration for $DEV:&amp;quot;&lt;br /&gt;
tc qdisc show dev $DEV&lt;br /&gt;
tc class show dev $DEV&lt;br /&gt;
tc filter show dev $DEV&lt;br /&gt;
#&lt;br /&gt;
# Outgoing traffic control&lt;br /&gt;
#&lt;br /&gt;
DEV=eth0&lt;br /&gt;
#&lt;br /&gt;
tc qdisc del dev $DEV root&lt;br /&gt;
#&lt;br /&gt;
tc qdisc add dev $DEV root handle 1: htb default 10&lt;br /&gt;
#&lt;br /&gt;
tc class add dev $DEV parent 1: classid 1:1 htb rate 100mbit burst 15k&lt;br /&gt;
tc class add dev $DEV parent 1:1 classid 1:10 htb rate 10mbit ceil 10mbit burst 15k&lt;br /&gt;
tc class add dev $DEV parent 1:1 classid 1:20 htb rate 20mbit ceil 20mbit burst 15k&lt;br /&gt;
tc class add dev $DEV parent 1:1 classid 1:30 htb rate 30mbit ceil 30mbit burst 15k&lt;br /&gt;
#&lt;br /&gt;
tc qdisc add dev $DEV parent 1:10 handle 10: sfq perturb 10&lt;br /&gt;
tc qdisc add dev $DEV parent 1:20 handle 20: sfq perturb 10&lt;br /&gt;
tc qdisc add dev $DEV parent 1:30 handle 30: sfq perturb 10&lt;br /&gt;
#&lt;br /&gt;
if [ ! -z $VE_IP1 ]; then&lt;br /&gt;
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip src &amp;quot;$VE_IP1&amp;quot; flowid 1:20&lt;br /&gt;
fi&lt;br /&gt;
if [ ! -z $VE_IP2 ]; then&lt;br /&gt;
    tc filter add dev $DEV protocol ip parent 1:0 prio 1 u32 match ip src &amp;quot;$VE_IP2&amp;quot; flowid 1:30&lt;br /&gt;
fi&lt;br /&gt;
#&lt;br /&gt;
echo;echo &amp;quot;tc configuration for $DEV:&amp;quot;&lt;br /&gt;
tc qdisc show dev $DEV&lt;br /&gt;
tc class show dev $DEV&lt;br /&gt;
tc filter show dev $DEV&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://lartc.org/howto/ Linux Advanced Routing &amp;amp; Traffic Control HOWTO]&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>BillW</name></author>
		
	</entry>
</feed>