<?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=Lithium</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=Lithium"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/Lithium"/>
	<updated>2026-05-13T18:01:09Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Monitoring_openvz_resources_using_yabeda&amp;diff=8146</id>
		<title>Monitoring openvz resources using yabeda</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Monitoring_openvz_resources_using_yabeda&amp;diff=8146"/>
		<updated>2010-01-29T11:45:53Z</updated>

		<summary type="html">&lt;p&gt;Lithium: /* What's yabeda, after all? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: Monitoring]]&lt;br /&gt;
&lt;br /&gt;
== What's yabeda, after all? ==&lt;br /&gt;
&lt;br /&gt;
Yabeda is an OpenVZ failcnt complainer which tends to be lightweight, flexible and easily extendable.&lt;br /&gt;
&lt;br /&gt;
Should be used on host machines (via some cron-job) to generate alerts when failcnt gets increased. Failcnt is the counter used in openvz kernels to tell whether the needed parameter reached its limit.&lt;br /&gt;
&lt;br /&gt;
The program is being written using Ruby aiming to have as little dependancies as possible. &lt;br /&gt;
&lt;br /&gt;
* Sends mails once any of your VE actually reached the barrier.&lt;br /&gt;
* Some other stuff is planned, check out the [http://yabeda.cryo.net.ru project home page]&lt;/div&gt;</summary>
		<author><name>Lithium</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=VPN_via_the_TUN/TAP_device&amp;diff=7558</id>
		<title>VPN via the TUN/TAP device</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=VPN_via_the_TUN/TAP_device&amp;diff=7558"/>
		<updated>2009-09-30T12:46:38Z</updated>

		<summary type="html">&lt;p&gt;Lithium: /* Kernel TUN/TAP support */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes how to use VPN via the TUN/TAP device inside a [[container]].&lt;br /&gt;
&lt;br /&gt;
== Kernel TUN/TAP support ==&lt;br /&gt;
OpenVZ supports VPN inside a container via kernel TUN/TAP module and device.&lt;br /&gt;
To allow container #101 to use the TUN/TAP device the following should be done:&lt;br /&gt;
&lt;br /&gt;
Make sure the '''tun''' module has been already loaded on the [[hardware node]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# lsmod | grep tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it is not there, use the following command to load '''tun''' module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# modprobe tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To make sure that '''tun''' module will be automatically loaded on every reboot you can also add it or into /etc/modules.conf (on RHEL see /etc/sysconfig/modules/ directory) or into /etc/sysconfig/vz-scripts/''CTID''.mount. (echo 'modprobe tun' &amp;gt;&amp;gt; /etc/sysconfig/vz-scripts/''CTID''.mount)&lt;br /&gt;
&lt;br /&gt;
== Granting container an access to TUN/TAP ==&lt;br /&gt;
Allow your container to use the tun/tap device by running the following commands on the host node:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --devices c:10:200:rw --save&lt;br /&gt;
 vzctl set 101 --capability net_admin:on --save&lt;br /&gt;
&lt;br /&gt;
And create the character device file inside the container (execute the following on the host node):&lt;br /&gt;
&lt;br /&gt;
 vzctl exec 101 mkdir -p /dev/net&lt;br /&gt;
 vzctl exec 101 mknod /dev/net/tun c 10 200&lt;br /&gt;
 vzctl exec 101 chmod 600 /dev/net/tun&lt;br /&gt;
&lt;br /&gt;
== Configuring VPN inside container ==&lt;br /&gt;
After the configuration steps above are done it is possible to use VPN software working with TUN/TAP inside&lt;br /&gt;
container just like on a usual standalone linux box.&lt;br /&gt;
&lt;br /&gt;
The following software can be used for VPN with TUN/TAP:&lt;br /&gt;
* Virtual TUNnel (http://vtun.sourceforge.net)&lt;br /&gt;
* OpenVPN (http://openvpn.sourceforge.net)&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
If NAT is needed within the VE, this error will occur on attempts to use NAT:&lt;br /&gt;
&lt;br /&gt;
 # iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j MASQUERADE&lt;br /&gt;
 iptables v1.4.3.2: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)&lt;br /&gt;
 Perhaps iptables or your kernel needs to be upgraded.&lt;br /&gt;
&lt;br /&gt;
The solution is given here:&lt;br /&gt;
&lt;br /&gt;
 http://kb.parallels.com/en/5228&lt;br /&gt;
&lt;br /&gt;
Also see page 69-70 of:&lt;br /&gt;
&lt;br /&gt;
 http://download.openvz.org/doc/OpenVZ-Users-Guide.pdf&lt;br /&gt;
&lt;br /&gt;
Note that the above steps do not solve the problem if a gentoo VE sits on a Centos HN; it's still an unsolved mystery.&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://vtun.sourceforge.net Virtual TUNnel]&lt;br /&gt;
* [http://openvpn.sourceforge.net OpenVPN]&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>Lithium</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=VPN_via_the_TUN/TAP_device&amp;diff=7557</id>
		<title>VPN via the TUN/TAP device</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=VPN_via_the_TUN/TAP_device&amp;diff=7557"/>
		<updated>2009-09-30T12:42:12Z</updated>

		<summary type="html">&lt;p&gt;Lithium: add notes about autoload tun module&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes how to use VPN via the TUN/TAP device inside a [[container]].&lt;br /&gt;
&lt;br /&gt;
== Kernel TUN/TAP support ==&lt;br /&gt;
OpenVZ supports VPN inside a container via kernel TUN/TAP module and device.&lt;br /&gt;
To allow container #101 to use the TUN/TAP device the following should be done:&lt;br /&gt;
&lt;br /&gt;
Make sure the '''tun''' module has been already loaded on the [[hardware node]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# lsmod | grep tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it is not there, use the following command to load '''tun''' module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# modprobe tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To make sure that '''tun''' module will be automatically loaded on every reboot you can also add it or into /etc/modules.conf (on RHEL: echo 'modprobe tun' &amp;gt;&amp;gt; /etc/sysconfig/modules/tun.modules) or into /etc/sysconfig/vz-scripts/''VEID''.mount. (echo 'modprobe tun' &amp;gt;&amp;gt; /etc/sysconfig/vz-scripts/''VEID''.mount)&lt;br /&gt;
&lt;br /&gt;
== Granting container an access to TUN/TAP ==&lt;br /&gt;
Allow your container to use the tun/tap device by running the following commands on the host node:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --devices c:10:200:rw --save&lt;br /&gt;
 vzctl set 101 --capability net_admin:on --save&lt;br /&gt;
&lt;br /&gt;
And create the character device file inside the container (execute the following on the host node):&lt;br /&gt;
&lt;br /&gt;
 vzctl exec 101 mkdir -p /dev/net&lt;br /&gt;
 vzctl exec 101 mknod /dev/net/tun c 10 200&lt;br /&gt;
 vzctl exec 101 chmod 600 /dev/net/tun&lt;br /&gt;
&lt;br /&gt;
== Configuring VPN inside container ==&lt;br /&gt;
After the configuration steps above are done it is possible to use VPN software working with TUN/TAP inside&lt;br /&gt;
container just like on a usual standalone linux box.&lt;br /&gt;
&lt;br /&gt;
The following software can be used for VPN with TUN/TAP:&lt;br /&gt;
* Virtual TUNnel (http://vtun.sourceforge.net)&lt;br /&gt;
* OpenVPN (http://openvpn.sourceforge.net)&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
If NAT is needed within the VE, this error will occur on attempts to use NAT:&lt;br /&gt;
&lt;br /&gt;
 # iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j MASQUERADE&lt;br /&gt;
 iptables v1.4.3.2: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)&lt;br /&gt;
 Perhaps iptables or your kernel needs to be upgraded.&lt;br /&gt;
&lt;br /&gt;
The solution is given here:&lt;br /&gt;
&lt;br /&gt;
 http://kb.parallels.com/en/5228&lt;br /&gt;
&lt;br /&gt;
Also see page 69-70 of:&lt;br /&gt;
&lt;br /&gt;
 http://download.openvz.org/doc/OpenVZ-Users-Guide.pdf&lt;br /&gt;
&lt;br /&gt;
Note that the above steps do not solve the problem if a gentoo VE sits on a Centos HN; it's still an unsolved mystery.&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://vtun.sourceforge.net Virtual TUNnel]&lt;br /&gt;
* [http://openvpn.sourceforge.net OpenVPN]&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>Lithium</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=OS_template_cache_preparation&amp;diff=7479</id>
		<title>OS template cache preparation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=OS_template_cache_preparation&amp;diff=7479"/>
		<updated>2009-08-21T08:31:11Z</updated>

		<summary type="html">&lt;p&gt;Lithium: add note about locale setup&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes the procedure of an OS template cache creation.  It assumes you already have OpenVZ installed and running. The steps needed to achieve it are documented in the [[Quick installation]] document.&lt;br /&gt;
&lt;br /&gt;
== Terminology ==&lt;br /&gt;
&lt;br /&gt;
Please make sure you understand the following terms.&lt;br /&gt;
&lt;br /&gt;
{{:OS template}}&lt;br /&gt;
{{:OS template metadata}}&lt;br /&gt;
{{:OS template cache}}&lt;br /&gt;
&lt;br /&gt;
== Creating an OS template cache ==&lt;br /&gt;
You can create an [[OS template cache]] using template utilities and [[OS template metadata]] right on your [[hardware node]]. The process is automated and will take from about 10 minutes to a few hours, depending on the network speed, and the result will be most up-to-date template cache.&lt;br /&gt;
&lt;br /&gt;
=== Installing template utilities ===&lt;br /&gt;
&lt;br /&gt;
You have to install a few packages in order to be able to create/update OS template cache(s).&lt;br /&gt;
&lt;br /&gt;
==== Using yum ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# yum install vzpkg vzyum vzrpm43-python vzrpm44-python vzctl-lib&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using rpm ====&lt;br /&gt;
Packages are available from [http://openvz.org/download/template/utils/ Download » Templates » Utilities]. You need both &amp;lt;tt&amp;gt;vzpkg&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;vzyum&amp;lt;/tt&amp;gt; packages, as well as one or both &amp;lt;tt&amp;gt;vzrpm43&amp;lt;/tt&amp;gt;/&amp;lt;tt&amp;gt;vzrpm44&amp;lt;/tt&amp;gt; (including their &amp;lt;tt&amp;gt;-python&amp;lt;/tt&amp;gt; counterparts), depending on the OS templates being used.&lt;br /&gt;
&lt;br /&gt;
Install these utilities using rpm:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rpm -ihv vzpkg*.rpm vzyum*.rpm vzrpm44*.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Red Hat Enterprise Linux, to install &amp;lt;tt&amp;gt;vzyum&amp;lt;/tt&amp;gt; you will need &amp;lt;tt&amp;gt;[http://rpmfind.net/linux/rpm2html/search.php?query=python-elementtree&amp;amp;system=redhat python-elementtree]&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;[http://rpmfind.net/linux/rpm2html/search.php?query=python-sqlite&amp;amp;system=redhat python-sqlite]&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;[http://rpmfind.net/linux/rpm2html/search.php?query=python-urlgrabber&amp;amp;system=redhat python-urlgrabber]&amp;lt;/tt&amp;gt;. These packages might have dependencies of their own. For example, &amp;lt;tt&amp;gt;python-sqlite&amp;lt;/tt&amp;gt; needs &amp;lt;tt&amp;gt;[http://rpmfind.net/linux/rpm2html/search.php?query=sqlite&amp;amp;system=redhat sqlite]&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Installing OS template metadata ===&lt;br /&gt;
&lt;br /&gt;
To create an [[OS template cache]], you need to get the [[OS template metadata|metadata]] for the chosen OS template(s).&lt;br /&gt;
&lt;br /&gt;
==== Using yum ====&lt;br /&gt;
To see which templates are available, run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# yum search vztmpl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To install some of the templates, run&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# yum install vztmpl-XXX [...]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Using rpm ====&lt;br /&gt;
Get the chosen &amp;lt;tt&amp;gt;vztmpl-*&amp;lt;/tt&amp;gt; packages from [http://openvz.org/download/template/metadata/ Downloads » Templates » Metadata] (or directly from [http://download.openvz.org/template/metadata/ download.openvz.org/template/metadata] or one of the [[Download mirrors|mirrors]] and install them:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# rpm -ihv vztmpl-*.rpm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Running &amp;lt;tt&amp;gt;vzpkgcache&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
&lt;br /&gt;
Run the &amp;lt;tt&amp;gt;vzpkgcache&amp;lt;/tt&amp;gt; utility; see the vzpkgcache(8) man page for details. It will create or update the caches of all the templates for which the corresponding metadata exist. Before cache creation be sure that you are set up all necessary locales for rpm (see [[Locales inside VE]]).&lt;br /&gt;
&lt;br /&gt;
 # vzpkgcache centos-4-i386-minimal&lt;br /&gt;
&lt;br /&gt;
== Alternative: use precreated template cache ==&lt;br /&gt;
&lt;br /&gt;
As an alternative to creating a cache using template metadata, you can use precreated template cache taken from [http://openvz.org/download/template/cache Downloads » Templates » Precreated], or directly from [http://download.openvz.org/template/precreated/ download.openvz.org/template/precreated], or from one of the [[Download mirrors|mirrors]].&lt;br /&gt;
&lt;br /&gt;
Precreated templates can be easily updated using the following algorithm:&lt;br /&gt;
# create temporary [[container]] based on template&lt;br /&gt;
# update [[container]] using OS-specific tools (yum, apt or similar)&lt;br /&gt;
# pack [[container]] as a new template&lt;br /&gt;
Examples of this procedure are described in details at [[Updating Ubuntu template]], [[Updating Debian template]], [[Fedora template update]]&lt;br /&gt;
&lt;br /&gt;
In order to use precreated template cache files, download files for chosen OS distributions and place them as-is (no unpacking needed) to the &amp;lt;tt&amp;gt;/vz/template/cache&amp;lt;/tt&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
'''NOTE:''' On Ubuntu and probably recent Debian distros, the path is &amp;lt;tt&amp;gt;/var/lib/vz/template/cache&amp;lt;/tt&amp;gt; if you installed OpenVZ from the repositories.&lt;br /&gt;
&lt;br /&gt;
'''NOTE:''' If you use precreated CentOS-4 templates and wish to install software using vzyum, you will probably run into error like this:&lt;br /&gt;
&lt;br /&gt;
 [root@localhost tmp]# vzyum CTID install mypackage&lt;br /&gt;
 [root@localhost tmp]# ERROR: No such OS template: install&lt;br /&gt;
&lt;br /&gt;
This might apply to Fedora also. To fix this problem, install the appropriate [[OS template metadata]] on the OpenVZ host, for example&lt;br /&gt;
&lt;br /&gt;
 yum install vztmpl-centos-4&lt;br /&gt;
&lt;br /&gt;
[Unverified note] : After creating a new OSTemplate cache called &amp;quot;centos4-i386-[ASINGLEWORD].tar.gz from a Container (on which vzyum worked) based on centos4-i386-default.tar.gz, vzyum failed to work (showing &amp;quot;No such OS template: install&amp;quot;). &lt;br /&gt;
&lt;br /&gt;
Here is the &amp;quot;solution&amp;quot; I worked out :&lt;br /&gt;
The new OSTemplate should be named &amp;quot;centos4-i386-[ASINGLEWORD].tar.gz&amp;quot;, and in /vz/template/centos/4/i386/config you should copy the default.list to [ASINGLEWORD].list. vzyum then works (for me!). I have tried to verify this by creating templates with [MULTIPLEWORDS], which fail, and by creating templates without a corresponding [ASINGLEWORLD].conf file, which also fail - indicating that using a single word seems to be important (no hyphens etc). Good luck.&lt;br /&gt;
&lt;br /&gt;
== Next step ==&lt;br /&gt;
&lt;br /&gt;
Follow on to the [[container creation]] article.&lt;br /&gt;
&lt;br /&gt;
[[Category: Installation]]&lt;br /&gt;
[[Category: Templates]]&lt;/div&gt;</summary>
		<author><name>Lithium</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_network_device&amp;diff=7453</id>
		<title>Virtual network device</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Virtual_network_device&amp;diff=7453"/>
		<updated>2009-07-29T12:30:41Z</updated>

		<summary type="html">&lt;p&gt;Lithium: added notes about filtering src/dst ip-addresses&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Virtual network device (&amp;lt;code&amp;gt;venet&amp;lt;/code&amp;gt;) is the default network device for a [[container]]. This network device looks like a point-to-point connection between [[container]] and the [[CT0|host system]]. It does packet switching based on IP header. This is a default network device for container (an alternative is [[veth]] device).&lt;br /&gt;
&lt;br /&gt;
Venet drop ip-packets '''from''' the container with a source address, and '''in''' the container with the destination address, which is not corresponding to an ip-address of the container.&lt;br /&gt;
&lt;br /&gt;
Venet device is created automatically on [[container]] start. Vzctl scripts set up an appropriate IP address and other settings on venet inside a container.&lt;br /&gt;
&lt;br /&gt;
==  Usage ==&lt;br /&gt;
&lt;br /&gt;
== Kernel module ==&lt;br /&gt;
First of all, check that &amp;lt;code&amp;gt;vznetdev&amp;lt;/code&amp;gt; module is loaded:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# lsmod | grep vznetdev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it is not, load the module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# modprobe vznetdev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You might want to check /etc/init.d/vz script to make sure the module gets loaded during startup.&lt;br /&gt;
&lt;br /&gt;
=== Adding IP address to a container ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set &amp;lt;CTID&amp;gt; --ipadd &amp;lt;IP1&amp;gt;[,&amp;lt;IP2&amp;gt;,...] [--save]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|This option is incremental, so IP addresses are added to already existing ones.}}&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 101 --ipadd 10.0.0.1 --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After executing this command IP address 10.0.0.1 will be added to container 101 and IP configuration will be saved to a container configuration file.&lt;br /&gt;
&lt;br /&gt;
=== Removing IP address from a container ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set &amp;lt;CTID&amp;gt; --ipdel &amp;lt;IP1&amp;gt;[,&amp;lt;IP2&amp;gt;,...] [--save]&lt;br /&gt;
vzctl set &amp;lt;CTID&amp;gt; --ipdel all [--save]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
vzctl set 101 --ipdel 10.0.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
After executing this command IP address 10.0.0.1 will be removed from container 101, but IP configuration will not be changed in container config file. And after container reboot IP address 10.0.0.1 will be assigned to this container again.&lt;br /&gt;
&lt;br /&gt;
== Sysctl ==&lt;br /&gt;
&lt;br /&gt;
You will need to configure some sysctl parameters to get your venet devices working.&lt;br /&gt;
Please have a look at the [[Installation_on_Debian#sysctl]] section.&lt;br /&gt;
&lt;br /&gt;
== IPv6 ==&lt;br /&gt;
&lt;br /&gt;
To setup IPv6 networking with venet you'll need to enable the following in your sysctl.conf:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
    # IPv6 Packet Forwarding and Proxy NDP &lt;br /&gt;
    net.ipv6.conf.default.forwarding = 1&lt;br /&gt;
    net.ipv6.conf.all.forwarding     = 1&lt;br /&gt;
    net.ipv6.conf.default.proxy_ndp = 1&lt;br /&gt;
    net.ipv6.conf.all.proxy_ndp = 1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In IPv6 you can't control forwarding per device, forwarding control has to take place in ip6tables, so all interfaces will forward IPv6 traffic. &lt;br /&gt;
&lt;br /&gt;
If you enable IPv6 forwarding for your interfaces, Linux assumes your host to act like a router and will ignore 'Router Advertisments' &lt;br /&gt;
(see [http://en.wikipedia.org/wiki/Neighbor_Discovery_Protocol Neighbor Discovery Protocol] or [http://mirrors.bieringer.de/Linux+IPv6-HOWTO/proc-sys-net-ipv6.html Linux IPv6 Howto]).&lt;br /&gt;
&lt;br /&gt;
You will as well need to configure a new v6 default gateway for your host:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
    ip addr add 2620:0:2d0:1::193/64 dev eth0&lt;br /&gt;
    route -6 add default gw 2620:0:2d0:1::1&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can add these commands to your existing network configuration on Debian/Linux:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
    iface eth0 inet static&lt;br /&gt;
        address 64.131.90.7&lt;br /&gt;
        netmask 255.255.255.240&lt;br /&gt;
        network 64.131.90.0&lt;br /&gt;
        broadcast 64.131.90.15&lt;br /&gt;
        gateway 64.131.90.1&lt;br /&gt;
        up   ip addr add 2620:0:2d0:1::193/64 dev eth0&lt;br /&gt;
        up   route -6 add default gw 2620:0:2d0:1::1&lt;br /&gt;
        down ip addr del 3620:0:2d0:1::193/64 dev eth0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Veth]]&lt;br /&gt;
* [[Differences between venet and veth]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Networking]]&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>Lithium</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_Ethernet_device&amp;diff=7452</id>
		<title>Virtual Ethernet device</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Virtual_Ethernet_device&amp;diff=7452"/>
		<updated>2009-07-29T11:40:35Z</updated>

		<summary type="html">&lt;p&gt;Lithium: /* Making a veth-device persistent */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Virtual Ethernet device''' is an Ethernet-like device which can be used&lt;br /&gt;
inside a [[container]]. Unlike [[venet]] network device, [[veth]] device&lt;br /&gt;
has a MAC address, therefore it can be used in configurations, when veth&lt;br /&gt;
is bridged to ethX or other device and container's user fully sets up&lt;br /&gt;
his networking himself, including IPs, gateways etc.&lt;br /&gt;
&lt;br /&gt;
Virtual Ethernet device consist of two Ethernet devices --&lt;br /&gt;
the one in [[CT0]] and another one in CT. These devices are connected&lt;br /&gt;
to each other, so if a packet goes to one&lt;br /&gt;
device it will come out from the other device.&lt;br /&gt;
&lt;br /&gt;
== Virtual Ethernet device usage ==&lt;br /&gt;
&lt;br /&gt;
=== Kernel module ===&lt;br /&gt;
First of all, make sure the &amp;lt;code&amp;gt;vzethdev&amp;lt;/code&amp;gt; module is loaded:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# lsmod | grep vzeth&lt;br /&gt;
vzethdev                8224  0&lt;br /&gt;
vzmon                  35164  5 vzethdev,vznetdev,vzrst,vzcpt&lt;br /&gt;
vzdev                   3080  4 vzethdev,vznetdev,vzmon,vzdquota&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case it is not loaded, load it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# modprobe vzethdev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|in vzctl &amp;lt; 3.0.11, vzethdev is not autoloaded by &amp;lt;code&amp;gt;/etc/init.d/vz&amp;lt;/code&amp;gt; script, so you have to edit it to load this module.}}&lt;br /&gt;
&lt;br /&gt;
=== MAC addresses ===&lt;br /&gt;
In the below commands, you should use random MAC addresses. Do not use MAC addresses of real eth devices, because this can lead to collisions.&lt;br /&gt;
&lt;br /&gt;
MAC addresses must be entered in XX:XX:XX:XX:XX:XX format.&lt;br /&gt;
&lt;br /&gt;
YOU MAY NOT NEED TO GENERATE MAC ADDRESSES BY HAND BECAUSE vzctl --veth_add&lt;br /&gt;
MAY GENERATE THEM AUTOMATICALLY AS NECESSARY.&lt;br /&gt;
&lt;br /&gt;
Nevertheless, there is a utility script available for generating MAC addresses: http://www.easyvmx.com/software/easymac.sh. It is to be used like this:&lt;br /&gt;
&lt;br /&gt;
 chmod +x easymac.sh&lt;br /&gt;
 ./easymac.sh -R&lt;br /&gt;
&lt;br /&gt;
=== Adding veth to a CT ===&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;gt; 3.0.22 ====&lt;br /&gt;
&lt;br /&gt;
 vzctl set &amp;lt;CTID&amp;gt; --netif_add &amp;lt;ifname&amp;gt;[,&amp;lt;mac&amp;gt;,&amp;lt;host_ifname&amp;gt;,&amp;lt;host_mac&amp;gt;,&amp;lt;bridge&amp;gt;]&lt;br /&gt;
&lt;br /&gt;
Here&lt;br /&gt;
* &amp;lt;tt&amp;gt;ifname&amp;lt;/tt&amp;gt; is the Ethernet device name in the CT&lt;br /&gt;
* &amp;lt;tt&amp;gt;mac&amp;lt;/tt&amp;gt; is its MAC address in the CT&lt;br /&gt;
* &amp;lt;tt&amp;gt;host_ifname&amp;lt;/tt&amp;gt;  is the Ethernet device name on the host ([[CT0]])&lt;br /&gt;
* &amp;lt;tt&amp;gt;host_mac&amp;lt;/tt&amp;gt; is its MAC address on the host ([[CT0]])&lt;br /&gt;
* &amp;lt;tt&amp;gt;bridge&amp;lt;/tt&amp;gt; is an optional parameter which can be used in custom network start scripts to automatically add  the interface to a bridge.&lt;br /&gt;
&lt;br /&gt;
{{Note|All parameters except &amp;lt;code&amp;gt;ifname&amp;lt;/code&amp;gt; are optional and are automatically generated if not specified.}}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --netif_add eth0 --save&lt;br /&gt;
&lt;br /&gt;
Or, if you want to specify everything:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --netif_add eth0,00:12:34:56:78:9A,veth101.0,00:12:34:56:78:9B --save&lt;br /&gt;
&lt;br /&gt;
Or, if you want to specify the bridge and leave the other values autogenerated:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --netif_add eth0,,,,vmbr1 --save&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;gt;= 3.0.14 ====&lt;br /&gt;
&lt;br /&gt;
Syntax is the same as above, but without a &amp;lt;bridge&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;lt; 3.0.14 ====&lt;br /&gt;
&lt;br /&gt;
 vzctl set &amp;lt;CTID&amp;gt; --veth_add &amp;lt;dev_name&amp;gt;,&amp;lt;dev_addr&amp;gt;,&amp;lt;ve_dev_name&amp;gt;,&amp;lt;ve_dev_addr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here &lt;br /&gt;
* &amp;lt;tt&amp;gt;dev_name&amp;lt;/tt&amp;gt; is the Ethernet device name that you are creating on the [[CT0|host system]]&lt;br /&gt;
* &amp;lt;tt&amp;gt;dev_addr&amp;lt;/tt&amp;gt; is its MAC address&lt;br /&gt;
* &amp;lt;tt&amp;gt;ve_dev_name&amp;lt;/tt&amp;gt; is the corresponding Ethernet device name you are creating on the CT&lt;br /&gt;
* &amp;lt;tt&amp;gt;ve_dev_addr&amp;lt;/tt&amp;gt; is its MAC address&lt;br /&gt;
&lt;br /&gt;
{{Note|this option is incremental, so devices are added to already existing ones.}}&lt;br /&gt;
&lt;br /&gt;
NB there should no spaces after the commas.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node] ifconfig eth0&lt;br /&gt;
...&lt;br /&gt;
HWaddress 00:12:34:56:78:9B&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [host-node] easymac.sh -R&lt;br /&gt;
 00:12:34:56:78:9A&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --veth_add veth101.0,00:12:34:56:78:9A,eth0,00:12:34:56:78:9B --save&lt;br /&gt;
&lt;br /&gt;
After executing this command &amp;lt;tt&amp;gt;veth&amp;lt;/tt&amp;gt; device will be created for CT 101 and veth configuration will be saved to a CT configuration file.&lt;br /&gt;
Host-side Ethernet device will have &amp;lt;tt&amp;gt;veth101.0&amp;lt;/tt&amp;gt; name and &amp;lt;tt&amp;gt;00:12:34:56:78:9A&amp;lt;/tt&amp;gt; MAC address.&lt;br /&gt;
CT-side Ethernet device will have &amp;lt;tt&amp;gt;eth0&amp;lt;/tt&amp;gt; name and &amp;lt;tt&amp;gt;00:12:34:56:78:9B&amp;lt;/tt&amp;gt; MAC address.&lt;br /&gt;
&lt;br /&gt;
=== Removing veth from a CT ===&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;gt;= 3.0.14 ====&lt;br /&gt;
&lt;br /&gt;
 vzctl set &amp;lt;CTID&amp;gt; --netif_del &amp;lt;dev_name&amp;gt;|all&lt;br /&gt;
&lt;br /&gt;
Here&lt;br /&gt;
* &amp;lt;code&amp;gt;dev_name&amp;lt;/code&amp;gt; is the Ethernet device name in the [[CT]].&lt;br /&gt;
&lt;br /&gt;
{{Note|If you want to remove all Ethernet devices in CT, use &amp;lt;code&amp;gt;all&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --netif_del eth0 --save&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;lt; 3.0.14 ====&lt;br /&gt;
&lt;br /&gt;
 vzctl set &amp;lt;CTID&amp;gt; --veth_del &amp;lt;dev_name&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;tt&amp;gt;dev_name&amp;lt;/tt&amp;gt; is the Ethernet device name in the [[CT0|host system]].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --veth_del veth101.0 --save&lt;br /&gt;
&lt;br /&gt;
After executing this command veth device with host-side Ethernet name&lt;br /&gt;
&amp;lt;code&amp;gt;veth101.0&amp;lt;/code&amp;gt; will be removed from CT101 and veth configuration&lt;br /&gt;
will be updated in CT config file.&lt;br /&gt;
&lt;br /&gt;
== Common configurations with virtual Ethernet devices ==&lt;br /&gt;
Module &amp;lt;tt&amp;gt;vzethdev&amp;lt;/tt&amp;gt; must be loaded to operate with veth devices.&lt;br /&gt;
&lt;br /&gt;
=== Simple configuration with virtual Ethernet device ===&lt;br /&gt;
&lt;br /&gt;
==== Start a CT ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl start 101&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Add veth device to CT ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl set 101 --netif_add eth0 --save&lt;br /&gt;
&lt;br /&gt;
This allocates a MAC address and associates it with the host eth0 port.&lt;br /&gt;
&lt;br /&gt;
==== Configure devices in CT0 ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ifconfig veth101.0 0&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/veth101.0/forwarding&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/veth101.0/proxy_arp&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/eth0/forwarding&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/eth0/proxy_arp&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* These files did not exist for me when trying ([[User:Mrjcleaver|Mrjcleaver]] 14:04, 31 May 2008 (EDT))&lt;br /&gt;
&lt;br /&gt;
==== Configure device in CT ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# vzctl enter 101&lt;br /&gt;
[ve-101]# /sbin/ifconfig eth0 0&lt;br /&gt;
[ve-101]# /sbin/ip addr add 192.168.0.101 dev eth0&lt;br /&gt;
[ve-101]# /sbin/ip route add default dev eth0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Until you ifconfig eth0 it won't appear. When you do it will use the mac address netif_add added earlier&lt;br /&gt;
* 192.168.0.101 is chosen to be an [[unrouteable private ip address]]. Where 101 reminds you that it is node 101.&lt;br /&gt;
* The &amp;quot;ip route&amp;quot; tells all traffic to head to &amp;quot;device eth0&amp;quot;&lt;br /&gt;
* In theory you could [[use dhcpd with OpenVZ]] and dhclient to pick up an DHCP address from your router instead of hardwiring it&lt;br /&gt;
** http://openvz.org/pipermail/users/2005-November/000020.html&lt;br /&gt;
&lt;br /&gt;
==== Add route in [[CT0]] ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# ip route add 192.168.0.101 dev veth101.0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Virtual Ethernet device with IPv6 ===&lt;br /&gt;
&lt;br /&gt;
==== Start a [[CT]] ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl start 101&lt;br /&gt;
&lt;br /&gt;
==== Add veth device to the [[CT]] ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl set 101 --veth_add eth0,00:12:34:56:78:9A,eth0,00:12:34:56:78:9B --save&lt;br /&gt;
&lt;br /&gt;
==== Configure devices in the [[CT0]] ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# ifconfig veth101.0 0&lt;br /&gt;
 [host-node]# echo 1 &amp;gt; /proc/sys/net/ipv6/conf/veth101.0/forwarding&lt;br /&gt;
 [host-node]# echo 1 &amp;gt; /proc/sys/net/ipv6/conf/eth0/forwarding&lt;br /&gt;
 [host-node]# echo 1 &amp;gt; /proc/sys/net/ipv6/conf/all/forwarding&lt;br /&gt;
&lt;br /&gt;
==== Configure device in [[CT]] ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl enter 101&lt;br /&gt;
 [ve-101]# /sbin/ifconfig eth0 0&lt;br /&gt;
&lt;br /&gt;
==== Start router advertisement daemon (radvd) for IPv6 in CT0 ====&lt;br /&gt;
First you need to edit radvd configuration file. Here is a simple example of &amp;lt;tt&amp;gt;/etc/radv.conf&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface veth101.0&lt;br /&gt;
{&lt;br /&gt;
        AdvSendAdvert on;&lt;br /&gt;
        MinRtrAdvInterval 3;&lt;br /&gt;
        MaxRtrAdvInterval 10;&lt;br /&gt;
        AdvHomeAgentFlag off;&lt;br /&gt;
&lt;br /&gt;
        prefix 3ffe:2400:0:0::/64&lt;br /&gt;
        {&lt;br /&gt;
                AdvOnLink on;&lt;br /&gt;
                AdvAutonomous on;&lt;br /&gt;
                AdvRouterAddr off;&lt;br /&gt;
        };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
interface eth0&lt;br /&gt;
{&lt;br /&gt;
        AdvSendAdvert on;&lt;br /&gt;
        MinRtrAdvInterval 3;&lt;br /&gt;
        MaxRtrAdvInterval 10;&lt;br /&gt;
        AdvHomeAgentFlag off;&lt;br /&gt;
&lt;br /&gt;
        prefix 3ffe:0302:0011:0002::/64&lt;br /&gt;
        {&lt;br /&gt;
                AdvOnLink on;&lt;br /&gt;
                AdvAutonomous on;&lt;br /&gt;
                AdvRouterAddr off;&lt;br /&gt;
        };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, start radvd:&lt;br /&gt;
&lt;br /&gt;
 [host-node]# /etc/init.d/radvd start&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Add IPv6 addresses to devices in [[CT0]] ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ip addr add dev veth101.0 3ffe:2400::212:34ff:fe56:789a/64&lt;br /&gt;
[host-node]# ip addr add dev eth0 3ffe:0302:0011:0002:211:22ff:fe33:4455/64&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Virtual Ethernet devices can be joined in one bridge ===&lt;br /&gt;
Perform steps 1 - 4 from Simple configuration chapter for several containers and/or veth devices&lt;br /&gt;
&lt;br /&gt;
==== Create bridge device ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# brctl addbr vzbr0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add veth devices to bridge ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# brctl addif vzbr0 veth101.0&lt;br /&gt;
...&lt;br /&gt;
[host-node]# brctl addif vzbr0 veth101.n&lt;br /&gt;
[host-node]# brctl addif vzbr0 veth102.0&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
[host-node]# brctl addif vzbr0 vethXXX.N&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configure bridge device ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ifconfig vzbr0 0&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/vzbr0/forwarding&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/vzbr0/proxy_arp&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add routes in [[CT0]] ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ip route add 192.168.101.1 dev vzbr0&lt;br /&gt;
...&lt;br /&gt;
[host-node]# ip route add 192.168.101.n dev vzbr0&lt;br /&gt;
[host-node]# ip route add 192.168.102.1 dev vzbr0&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
[host-node]# ip route add 192.168.XXX.N dev vzbr0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus you'll have more convinient configuration, i.e. all routes to containers will be through this bridge and containers can communicate with each other even without these routes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Making a veth-device persistent ===&lt;br /&gt;
According to http://bugzilla.openvz.org/show_bug.cgi?id=301 , a bug that stopped the veth device persistent was &amp;quot;Obsoleted now when --veth_add/--veth_del are introduced&amp;quot;&lt;br /&gt;
&lt;br /&gt;
See http://wiki.openvz.org/w/index.php?title=Virtual_Ethernet_device&amp;amp;diff=5990&amp;amp;oldid=5989#Making_a_veth-device_persistent for a workaround that used to be described in this section.&lt;br /&gt;
&lt;br /&gt;
That's it! At this point, when you restart the CT you should see a new line in the output, indicating that the interface is being configured and a new route being added. And you should be able to ping the host, and to enter the CT and use the network.&lt;br /&gt;
&lt;br /&gt;
=== Making a bridged veth-device persistent ===&lt;br /&gt;
&lt;br /&gt;
Like the above example, here it is how to add the veth device to a bridge in a persistent way. &lt;br /&gt;
&lt;br /&gt;
==== method for vzctl version &amp;gt; 3.0.22 ====&lt;br /&gt;
&lt;br /&gt;
Newer versions of vzctl includes a 'vznetaddbr' script, which makes use of the new &amp;lt;bridge&amp;gt; parameter of the --netif_add switch.&lt;br /&gt;
&lt;br /&gt;
Just create /etc/vz/vznet.conf containing the following.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
EXTERNAL_SCRIPT=&amp;quot;/usr/sbin/vznetaddbr&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script uses 'vmbr0' as default bridge name when no bridge is specified.&lt;br /&gt;
&lt;br /&gt;
==== method for vzctl version &amp;lt;= 3.0.22 ====&lt;br /&gt;
&lt;br /&gt;
Older vzctl doesn't offer an automatic function to do this.&lt;br /&gt;
&lt;br /&gt;
1. First, edit the CT's configuration to specify what is the host bridge , and to indicate that a custom script should be run when starting up a CT.&lt;br /&gt;
* Open up /etc/vz/conf/CTID.conf&lt;br /&gt;
* Comment out any IP_ADDRESS entries to prevent a CTNET-device from being created in the CT&lt;br /&gt;
* Add or change the entry CONFIG_CUSTOMIZED=&amp;quot;yes&amp;quot;&lt;br /&gt;
* Add an entry VZHOSTBR=&amp;quot;&amp;lt;bridge if&amp;gt;&amp;quot; which is the bridge interface (already configured and up), you want to extend.&lt;br /&gt;
&lt;br /&gt;
2. Now to create that &amp;quot;custom script&amp;quot;. The following helper script will check the configuration file for the bridge interface name and for the veth interface, and add the interface to the bridge. Create the script /usr/sbin/vznetaddbr to have the following, and then &amp;lt;code&amp;gt;chmod 0500 /usr/sbin/vznetaddbr&amp;lt;/code&amp;gt; to make it executable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# /usr/sbin/vznetaddbr&lt;br /&gt;
# a script to add virtual network interfaces (veth's) in a CT to a bridge on CT0&lt;br /&gt;
&lt;br /&gt;
CONFIGFILE=/etc/vz/conf/$VEID.conf&lt;br /&gt;
. $CONFIGFILE&lt;br /&gt;
VZHOSTIF=`echo $NETIF |sed 's/^.*host_ifname=\(.*\),.*$/\1/g'`&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VZHOSTIF&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;According to $CONFIGFILE CT$VEID has no veth interface configured.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VZHOSTBR&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;According to $CONFIGFILE CT$VEID has no bridge interface configured.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding interface $VZHOSTIF to bridge $VZHOSTBR on CT0 for CT$VEID&amp;quot;&lt;br /&gt;
/sbin/ifconfig $VZHOSTIF 0&lt;br /&gt;
echo 1 &amp;gt; /proc/sys/net/ipv4/conf/$VZHOSTIF/proxy_arp&lt;br /&gt;
echo 1 &amp;gt; /proc/sys/net/ipv4/conf/$VZHOSTIF/forwarding&lt;br /&gt;
/usr/sbin/brctl addif $VZHOSTBR $VZHOSTIF&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Now create /etc/vz/vznet.conf containing the following. This is what defines the &amp;quot;custom script&amp;quot; as being the vznetaddbr which you just created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
EXTERNAL_SCRIPT=&amp;quot;/usr/sbin/vznetaddbr&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This may not work for particularily old versions of vzctl, e.g., the version 3.0.11 that ships with Debian Etch. For those versions, you can try a hack: Use the custom script &amp;lt;code&amp;gt;/etc/vz/conf/$VID.mount&amp;lt;/code&amp;gt; which is available, even in these old versions. But it gets called too early, before the networking has been set up. But it can start some background process, which waits and occasionally polls until $VZHOSTIF has become available. Here is one way to go about it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
CONFIGFILE=&amp;quot;/etc/vz/conf/$VEID.conf&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ -f &amp;quot;$CONFIGFILE&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
   . &amp;quot;$CONFIGFILE&amp;quot;&lt;br /&gt;
   VZHOSTIF=`echo $NETIF |sed 's/^.*host_ifname=\(.*\),.*$/\1/g'`&lt;br /&gt;
   export VZHOSTIF&lt;br /&gt;
   export VZHOSTBR&lt;br /&gt;
&lt;br /&gt;
   # Fork into the background and try a few times,&lt;br /&gt;
   # until the host side of the interface appears:&lt;br /&gt;
   /bin/bash -c 'for i in 5 10 20 40 80 160&lt;br /&gt;
     do&lt;br /&gt;
        if ifconfig -a | grep -q &amp;quot;$VZHOSTIF&amp;quot;&lt;br /&gt;
        then&lt;br /&gt;
           exec /usr/sbin/vznetaddbr&lt;br /&gt;
        else&lt;br /&gt;
           sleep &amp;quot;$i&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
     done&lt;br /&gt;
   ' &amp;amp;&lt;br /&gt;
&lt;br /&gt;
   # In the meantime, let the CT's start process continue,&lt;br /&gt;
   # or else the interface will never appear:&lt;br /&gt;
   exit 0&lt;br /&gt;
else&lt;br /&gt;
   $0: Config file &amp;quot;$CONFIGFILE&amp;quot; does not exist.&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Of course, the CT's operating system will need to have . Consult the manual for your CT's OS for details.&lt;br /&gt;
&lt;br /&gt;
When the CT is started, the veth specified in the NETIF value is added to the bridge specified. You can check this by doing &amp;lt;code&amp;gt;brctl show&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside the CT you can configure the interface statically or using dhcp, as a real interface attached to a switch on the lan.&lt;br /&gt;
&lt;br /&gt;
=== Virtual Ethernet devices + VLAN ===&lt;br /&gt;
This configuration can be done by adding vlan device to the previous configuration.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Virtual network device]]&lt;br /&gt;
* [[Differences between venet and veth]]&lt;br /&gt;
* [[Using private IPs for Hardware Nodes]]&lt;br /&gt;
* Troubleshooting: [[Bridge doesn't forward packets]]&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://www.tldp.org/HOWTO/Linux+IPv6-HOWTO/hints-daemons-radvd.html Linux IPv6 HOWTO, a chapter about radvd]&lt;br /&gt;
* [http://vireso.blogspot.com/2008/02/2-veth-with-2-brindges-on-openvz-at.html 2 veth with 2 bridges setup]&lt;br /&gt;
&lt;br /&gt;
[[Category: Networking]]&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>Lithium</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_Ethernet_device&amp;diff=7441</id>
		<title>Virtual Ethernet device</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Virtual_Ethernet_device&amp;diff=7441"/>
		<updated>2009-07-24T13:25:50Z</updated>

		<summary type="html">&lt;p&gt;Lithium: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Virtual Ethernet device''' is an Ethernet-like device which can be used&lt;br /&gt;
inside a [[container]]. Unlike [[venet]] network device, [[veth]] device&lt;br /&gt;
has a MAC address, therefore it can be used in configurations, when veth&lt;br /&gt;
is bridged to ethX or other device and container's user fully sets up&lt;br /&gt;
his networking himself, including IPs, gateways etc.&lt;br /&gt;
&lt;br /&gt;
Virtual Ethernet device consist of two Ethernet devices --&lt;br /&gt;
the one in [[CT0]] and another one in CT. These devices are connected&lt;br /&gt;
to each other, so if a packet goes to one&lt;br /&gt;
device it will come out from the other device.&lt;br /&gt;
&lt;br /&gt;
== Virtual Ethernet device usage ==&lt;br /&gt;
&lt;br /&gt;
=== Kernel module ===&lt;br /&gt;
First of all, make sure the &amp;lt;code&amp;gt;vzethdev&amp;lt;/code&amp;gt; module is loaded:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# lsmod | grep vzeth&lt;br /&gt;
vzethdev                8224  0&lt;br /&gt;
vzmon                  35164  5 vzethdev,vznetdev,vzrst,vzcpt&lt;br /&gt;
vzdev                   3080  4 vzethdev,vznetdev,vzmon,vzdquota&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In case it is not loaded, load it:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# modprobe vzethdev&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|in vzctl &amp;lt; 3.0.11, vzethdev is not autoloaded by &amp;lt;code&amp;gt;/etc/init.d/vz&amp;lt;/code&amp;gt; script, so you have to edit it to load this module.}}&lt;br /&gt;
&lt;br /&gt;
=== MAC addresses ===&lt;br /&gt;
In the below commands, you should use random MAC addresses. Do not use MAC addresses of real eth devices, because this can lead to collisions.&lt;br /&gt;
&lt;br /&gt;
MAC addresses must be entered in XX:XX:XX:XX:XX:XX format.&lt;br /&gt;
&lt;br /&gt;
YOU MAY NOT NEED TO GENERATE MAC ADDRESSES BY HAND BECAUSE vzctl --veth_add&lt;br /&gt;
MAY GENERATE THEM AUTOMATICALLY AS NECESSARY.&lt;br /&gt;
&lt;br /&gt;
Nevertheless, there is a utility script available for generating MAC addresses: http://www.easyvmx.com/software/easymac.sh. It is to be used like this:&lt;br /&gt;
&lt;br /&gt;
 chmod +x easymac.sh&lt;br /&gt;
 ./easymac.sh -R&lt;br /&gt;
&lt;br /&gt;
=== Adding veth to a CT ===&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;gt; 3.0.22 ====&lt;br /&gt;
&lt;br /&gt;
 vzctl set &amp;lt;CTID&amp;gt; --netif_add &amp;lt;ifname&amp;gt;[,&amp;lt;mac&amp;gt;,&amp;lt;host_ifname&amp;gt;,&amp;lt;host_mac&amp;gt;,&amp;lt;bridge&amp;gt;]&lt;br /&gt;
&lt;br /&gt;
Here&lt;br /&gt;
* &amp;lt;tt&amp;gt;ifname&amp;lt;/tt&amp;gt; is the Ethernet device name in the CT&lt;br /&gt;
* &amp;lt;tt&amp;gt;mac&amp;lt;/tt&amp;gt; is its MAC address in the CT&lt;br /&gt;
* &amp;lt;tt&amp;gt;host_ifname&amp;lt;/tt&amp;gt;  is the Ethernet device name on the host ([[CT0]])&lt;br /&gt;
* &amp;lt;tt&amp;gt;host_mac&amp;lt;/tt&amp;gt; is its MAC address on the host ([[CT0]])&lt;br /&gt;
* &amp;lt;tt&amp;gt;bridge&amp;lt;/tt&amp;gt; is an optional parameter which can be used in custom network start scripts to automatically add  the interface to a bridge.&lt;br /&gt;
&lt;br /&gt;
{{Note|All parameters except &amp;lt;code&amp;gt;ifname&amp;lt;/code&amp;gt; are optional and are automatically generated if not specified.}}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --netif_add eth0 --save&lt;br /&gt;
&lt;br /&gt;
Or, if you want to specify everything:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --netif_add eth0,00:12:34:56:78:9A,veth101.0,00:12:34:56:78:9B --save&lt;br /&gt;
&lt;br /&gt;
Or, if you want to specify the bridge and leave the other values autogenerated:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --netif_add eth0,,,,vmbr1 --save&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;gt;= 3.0.14 ====&lt;br /&gt;
&lt;br /&gt;
Syntax is the same as above, but without a &amp;lt;bridge&amp;gt; parameter.&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;lt; 3.0.14 ====&lt;br /&gt;
&lt;br /&gt;
 vzctl set &amp;lt;CTID&amp;gt; --veth_add &amp;lt;dev_name&amp;gt;,&amp;lt;dev_addr&amp;gt;,&amp;lt;ve_dev_name&amp;gt;,&amp;lt;ve_dev_addr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here &lt;br /&gt;
* &amp;lt;tt&amp;gt;dev_name&amp;lt;/tt&amp;gt; is the Ethernet device name that you are creating on the [[CT0|host system]]&lt;br /&gt;
* &amp;lt;tt&amp;gt;dev_addr&amp;lt;/tt&amp;gt; is its MAC address&lt;br /&gt;
* &amp;lt;tt&amp;gt;ve_dev_name&amp;lt;/tt&amp;gt; is the corresponding Ethernet device name you are creating on the CT&lt;br /&gt;
* &amp;lt;tt&amp;gt;ve_dev_addr&amp;lt;/tt&amp;gt; is its MAC address&lt;br /&gt;
&lt;br /&gt;
{{Note|this option is incremental, so devices are added to already existing ones.}}&lt;br /&gt;
&lt;br /&gt;
NB there should no spaces after the commas.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node] ifconfig eth0&lt;br /&gt;
...&lt;br /&gt;
HWaddress 00:12:34:56:78:9B&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [host-node] easymac.sh -R&lt;br /&gt;
 00:12:34:56:78:9A&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --veth_add veth101.0,00:12:34:56:78:9A,eth0,00:12:34:56:78:9B --save&lt;br /&gt;
&lt;br /&gt;
After executing this command &amp;lt;tt&amp;gt;veth&amp;lt;/tt&amp;gt; device will be created for CT 101 and veth configuration will be saved to a CT configuration file.&lt;br /&gt;
Host-side Ethernet device will have &amp;lt;tt&amp;gt;veth101.0&amp;lt;/tt&amp;gt; name and &amp;lt;tt&amp;gt;00:12:34:56:78:9A&amp;lt;/tt&amp;gt; MAC address.&lt;br /&gt;
CT-side Ethernet device will have &amp;lt;tt&amp;gt;eth0&amp;lt;/tt&amp;gt; name and &amp;lt;tt&amp;gt;00:12:34:56:78:9B&amp;lt;/tt&amp;gt; MAC address.&lt;br /&gt;
&lt;br /&gt;
=== Removing veth from a CT ===&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;gt;= 3.0.14 ====&lt;br /&gt;
&lt;br /&gt;
 vzctl set &amp;lt;CTID&amp;gt; --netif_del &amp;lt;dev_name&amp;gt;|all&lt;br /&gt;
&lt;br /&gt;
Here&lt;br /&gt;
* &amp;lt;code&amp;gt;dev_name&amp;lt;/code&amp;gt; is the Ethernet device name in the [[CT]].&lt;br /&gt;
&lt;br /&gt;
{{Note|If you want to remove all Ethernet devices in CT, use &amp;lt;code&amp;gt;all&amp;lt;/code&amp;gt;.}}&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --netif_del eth0 --save&lt;br /&gt;
&lt;br /&gt;
==== syntax vzctl version &amp;lt; 3.0.14 ====&lt;br /&gt;
&lt;br /&gt;
 vzctl set &amp;lt;CTID&amp;gt; --veth_del &amp;lt;dev_name&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;tt&amp;gt;dev_name&amp;lt;/tt&amp;gt; is the Ethernet device name in the [[CT0|host system]].&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --veth_del veth101.0 --save&lt;br /&gt;
&lt;br /&gt;
After executing this command veth device with host-side Ethernet name&lt;br /&gt;
&amp;lt;code&amp;gt;veth101.0&amp;lt;/code&amp;gt; will be removed from CT101 and veth configuration&lt;br /&gt;
will be updated in CT config file.&lt;br /&gt;
&lt;br /&gt;
== Common configurations with virtual Ethernet devices ==&lt;br /&gt;
Module &amp;lt;tt&amp;gt;vzethdev&amp;lt;/tt&amp;gt; must be loaded to operate with veth devices.&lt;br /&gt;
&lt;br /&gt;
=== Simple configuration with virtual Ethernet device ===&lt;br /&gt;
&lt;br /&gt;
==== Start a CT ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl start 101&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Add veth device to CT ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl set 101 --netif_add eth0 --save&lt;br /&gt;
&lt;br /&gt;
This allocates a MAC address and associates it with the host eth0 port.&lt;br /&gt;
&lt;br /&gt;
==== Configure devices in CT0 ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ifconfig veth101.0 0&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/veth101.0/forwarding&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/veth101.0/proxy_arp&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/eth0/forwarding&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/eth0/proxy_arp&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* These files did not exist for me when trying ([[User:Mrjcleaver|Mrjcleaver]] 14:04, 31 May 2008 (EDT))&lt;br /&gt;
&lt;br /&gt;
==== Configure device in CT ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# vzctl enter 101&lt;br /&gt;
[ve-101]# /sbin/ifconfig eth0 0&lt;br /&gt;
[ve-101]# /sbin/ip addr add 192.168.0.101 dev eth0&lt;br /&gt;
[ve-101]# /sbin/ip route add default dev eth0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Until you ifconfig eth0 it won't appear. When you do it will use the mac address netif_add added earlier&lt;br /&gt;
* 192.168.0.101 is chosen to be an [[unrouteable private ip address]]. Where 101 reminds you that it is node 101.&lt;br /&gt;
* The &amp;quot;ip route&amp;quot; tells all traffic to head to &amp;quot;device eth0&amp;quot;&lt;br /&gt;
* In theory you could [[use dhcpd with OpenVZ]] and dhclient to pick up an DHCP address from your router instead of hardwiring it&lt;br /&gt;
** http://openvz.org/pipermail/users/2005-November/000020.html&lt;br /&gt;
&lt;br /&gt;
==== Add route in [[CT0]] ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# ip route add 192.168.0.101 dev veth101.0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Virtual Ethernet device with IPv6 ===&lt;br /&gt;
&lt;br /&gt;
==== Start a [[CT]] ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl start 101&lt;br /&gt;
&lt;br /&gt;
==== Add veth device to the [[CT]] ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl set 101 --veth_add eth0,00:12:34:56:78:9A,eth0,00:12:34:56:78:9B --save&lt;br /&gt;
&lt;br /&gt;
==== Configure devices in the [[CT0]] ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# ifconfig veth101.0 0&lt;br /&gt;
 [host-node]# echo 1 &amp;gt; /proc/sys/net/ipv6/conf/veth101.0/forwarding&lt;br /&gt;
 [host-node]# echo 1 &amp;gt; /proc/sys/net/ipv6/conf/eth0/forwarding&lt;br /&gt;
 [host-node]# echo 1 &amp;gt; /proc/sys/net/ipv6/conf/all/forwarding&lt;br /&gt;
&lt;br /&gt;
==== Configure device in [[CT]] ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl enter 101&lt;br /&gt;
 [ve-101]# /sbin/ifconfig eth0 0&lt;br /&gt;
&lt;br /&gt;
==== Start router advertisement daemon (radvd) for IPv6 in CT0 ====&lt;br /&gt;
First you need to edit radvd configuration file. Here is a simple example of &amp;lt;tt&amp;gt;/etc/radv.conf&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface veth101.0&lt;br /&gt;
{&lt;br /&gt;
        AdvSendAdvert on;&lt;br /&gt;
        MinRtrAdvInterval 3;&lt;br /&gt;
        MaxRtrAdvInterval 10;&lt;br /&gt;
        AdvHomeAgentFlag off;&lt;br /&gt;
&lt;br /&gt;
        prefix 3ffe:2400:0:0::/64&lt;br /&gt;
        {&lt;br /&gt;
                AdvOnLink on;&lt;br /&gt;
                AdvAutonomous on;&lt;br /&gt;
                AdvRouterAddr off;&lt;br /&gt;
        };&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
interface eth0&lt;br /&gt;
{&lt;br /&gt;
        AdvSendAdvert on;&lt;br /&gt;
        MinRtrAdvInterval 3;&lt;br /&gt;
        MaxRtrAdvInterval 10;&lt;br /&gt;
        AdvHomeAgentFlag off;&lt;br /&gt;
&lt;br /&gt;
        prefix 3ffe:0302:0011:0002::/64&lt;br /&gt;
        {&lt;br /&gt;
                AdvOnLink on;&lt;br /&gt;
                AdvAutonomous on;&lt;br /&gt;
                AdvRouterAddr off;&lt;br /&gt;
        };&lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then, start radvd:&lt;br /&gt;
&lt;br /&gt;
 [host-node]# /etc/init.d/radvd start&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Add IPv6 addresses to devices in [[CT0]] ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ip addr add dev veth101.0 3ffe:2400::212:34ff:fe56:789a/64&lt;br /&gt;
[host-node]# ip addr add dev eth0 3ffe:0302:0011:0002:211:22ff:fe33:4455/64&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Virtual Ethernet devices can be joined in one bridge ===&lt;br /&gt;
Perform steps 1 - 4 from Simple configuration chapter for several containers and/or veth devices&lt;br /&gt;
&lt;br /&gt;
==== Create bridge device ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# brctl addbr vzbr0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add veth devices to bridge ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# brctl addif vzbr0 veth101.0&lt;br /&gt;
...&lt;br /&gt;
[host-node]# brctl addif vzbr0 veth101.n&lt;br /&gt;
[host-node]# brctl addif vzbr0 veth102.0&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
[host-node]# brctl addif vzbr0 vethXXX.N&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Configure bridge device ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ifconfig vzbr0 0&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/vzbr0/forwarding&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/conf/vzbr0/proxy_arp&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Add routes in [[CT0]] ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ip route add 192.168.101.1 dev vzbr0&lt;br /&gt;
...&lt;br /&gt;
[host-node]# ip route add 192.168.101.n dev vzbr0&lt;br /&gt;
[host-node]# ip route add 192.168.102.1 dev vzbr0&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
[host-node]# ip route add 192.168.XXX.N dev vzbr0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thus you'll have more convinient configuration, i.e. all routes to containers will be through this bridge and containers can communicate with each other even without these routes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Making a veth-device persistent ===&lt;br /&gt;
According to http://bugzilla.openvz.org/show_bug.cgi?id=301 , a bug that stopped the veth device persistent was &amp;quot;Obsoleted now when --veth_add/--veth_del are introduced&amp;quot;&lt;br /&gt;
&lt;br /&gt;
See http://wiki.openvz.org/w/index.php?title=Virtual_Ethernet_device&amp;amp;diff=5990&amp;amp;oldid=5989 for a workaround that used to be described in this section.&lt;br /&gt;
&lt;br /&gt;
That's it! At this point, when you restart the CT you should see a new line in the output, indicating that the interface is being configured and a new route being added. And you should be able to ping the host, and to enter the CT and use the network.&lt;br /&gt;
&lt;br /&gt;
=== Making a bridged veth-device persistent ===&lt;br /&gt;
&lt;br /&gt;
Like the above example, here it is how to add the veth device to a bridge in a persistent way. &lt;br /&gt;
&lt;br /&gt;
==== method for vzctl version &amp;gt; 3.0.22 ====&lt;br /&gt;
&lt;br /&gt;
Newer versions of vzctl includes a 'vznetaddbr' script, which makes use of the new &amp;lt;bridge&amp;gt; parameter of the --netif_add switch.&lt;br /&gt;
&lt;br /&gt;
Just create /etc/vz/vznet.conf containing the following.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
EXTERNAL_SCRIPT=&amp;quot;/usr/sbin/vznetaddbr&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script uses 'vmbr0' as default bridge name when no bridge is specified.&lt;br /&gt;
&lt;br /&gt;
==== method for vzctl version &amp;lt;= 3.0.22 ====&lt;br /&gt;
&lt;br /&gt;
Older vzctl doesn't offer an automatic function to do this.&lt;br /&gt;
&lt;br /&gt;
1. First, edit the CT's configuration to specify what is the host bridge , and to indicate that a custom script should be run when starting up a CT.&lt;br /&gt;
* Open up /etc/vz/conf/CTID.conf&lt;br /&gt;
* Comment out any IP_ADDRESS entries to prevent a CTNET-device from being created in the CT&lt;br /&gt;
* Add or change the entry CONFIG_CUSTOMIZED=&amp;quot;yes&amp;quot;&lt;br /&gt;
* Add an entry VZHOSTBR=&amp;quot;&amp;lt;bridge if&amp;gt;&amp;quot; which is the bridge interface (already configured and up), you want to extend.&lt;br /&gt;
&lt;br /&gt;
2. Now to create that &amp;quot;custom script&amp;quot;. The following helper script will check the configuration file for the bridge interface name and for the veth interface, and add the interface to the bridge. Create the script /usr/sbin/vznetaddbr to have the following, and then &amp;lt;code&amp;gt;chmod 0500 /usr/sbin/vznetaddbr&amp;lt;/code&amp;gt; to make it executable.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# /usr/sbin/vznetaddbr&lt;br /&gt;
# a script to add virtual network interfaces (veth's) in a CT to a bridge on CT0&lt;br /&gt;
&lt;br /&gt;
CONFIGFILE=/etc/vz/conf/$VEID.conf&lt;br /&gt;
. $CONFIGFILE&lt;br /&gt;
VZHOSTIF=`echo $NETIF |sed 's/^.*host_ifname=\(.*\),.*$/\1/g'`&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VZHOSTIF&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;According to $CONFIGFILE CT$VEID has no veth interface configured.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VZHOSTBR&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;According to $CONFIGFILE CT$VEID has no bridge interface configured.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Adding interface $VZHOSTIF to bridge $VZHOSTBR on CT0 for CT$VEID&amp;quot;&lt;br /&gt;
/sbin/ifconfig $VZHOSTIF 0&lt;br /&gt;
echo 1 &amp;gt; /proc/sys/net/ipv4/conf/$VZHOSTIF/proxy_arp&lt;br /&gt;
echo 1 &amp;gt; /proc/sys/net/ipv4/conf/$VZHOSTIF/forwarding&lt;br /&gt;
/usr/sbin/brctl addif $VZHOSTBR $VZHOSTIF&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
3. Now create /etc/vz/vznet.conf containing the following. This is what defines the &amp;quot;custom script&amp;quot; as being the vznetaddbr which you just created.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
EXTERNAL_SCRIPT=&amp;quot;/usr/sbin/vznetaddbr&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This may not work for particularily old versions of vzctl, e.g., the version 3.0.11 that ships with Debian Etch. For those versions, you can try a hack: Use the custom script &amp;lt;code&amp;gt;/etc/vz/conf/$VID.mount&amp;lt;/code&amp;gt; which is available, even in these old versions. But it gets called too early, before the networking has been set up. But it can start some background process, which waits and occasionally polls until $VZHOSTIF has become available. Here is one way to go about it:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
CONFIGFILE=&amp;quot;/etc/vz/conf/$VEID.conf&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ -f &amp;quot;$CONFIGFILE&amp;quot; ]&lt;br /&gt;
then&lt;br /&gt;
   . &amp;quot;$CONFIGFILE&amp;quot;&lt;br /&gt;
   VZHOSTIF=`echo $NETIF |sed 's/^.*host_ifname=\(.*\),.*$/\1/g'`&lt;br /&gt;
   export VZHOSTIF&lt;br /&gt;
   export VZHOSTBR&lt;br /&gt;
&lt;br /&gt;
   # Fork into the background and try a few times,&lt;br /&gt;
   # until the host side of the interface appears:&lt;br /&gt;
   /bin/bash -c 'for i in 5 10 20 40 80 160&lt;br /&gt;
     do&lt;br /&gt;
        if ifconfig -a | grep -q &amp;quot;$VZHOSTIF&amp;quot;&lt;br /&gt;
        then&lt;br /&gt;
           exec /usr/sbin/vznetaddbr&lt;br /&gt;
        else&lt;br /&gt;
           sleep &amp;quot;$i&amp;quot;&lt;br /&gt;
        fi&lt;br /&gt;
     done&lt;br /&gt;
   ' &amp;amp;&lt;br /&gt;
&lt;br /&gt;
   # In the meantime, let the CT's start process continue,&lt;br /&gt;
   # or else the interface will never appear:&lt;br /&gt;
   exit 0&lt;br /&gt;
else&lt;br /&gt;
   $0: Config file &amp;quot;$CONFIGFILE&amp;quot; does not exist.&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4. Of course, the CT's operating system will need to have . Consult the manual for your CT's OS for details.&lt;br /&gt;
&lt;br /&gt;
When the CT is started, the veth specified in the NETIF value is added to the bridge specified. You can check this by doing &amp;lt;code&amp;gt;brctl show&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Inside the CT you can configure the interface statically or using dhcp, as a real interface attached to a switch on the lan.&lt;br /&gt;
&lt;br /&gt;
=== Virtual Ethernet devices + VLAN ===&lt;br /&gt;
This configuration can be done by adding vlan device to the previous configuration.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Virtual network device]]&lt;br /&gt;
* [[Differences between venet and veth]]&lt;br /&gt;
* [[Using private IPs for Hardware Nodes]]&lt;br /&gt;
* Troubleshooting: [[Bridge doesn't forward packets]]&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://www.tldp.org/HOWTO/Linux+IPv6-HOWTO/hints-daemons-radvd.html Linux IPv6 HOWTO, a chapter about radvd]&lt;br /&gt;
* [http://vireso.blogspot.com/2008/02/2-veth-with-2-brindges-on-openvz-at.html 2 veth with 2 bridges setup]&lt;br /&gt;
&lt;br /&gt;
[[Category: Networking]]&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>Lithium</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=VPN_via_the_TUN/TAP_device&amp;diff=7437</id>
		<title>VPN via the TUN/TAP device</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=VPN_via_the_TUN/TAP_device&amp;diff=7437"/>
		<updated>2009-07-23T08:26:18Z</updated>

		<summary type="html">&lt;p&gt;Lithium: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes how to use VPN via the TUN/TAP device inside a [[container]].&lt;br /&gt;
&lt;br /&gt;
== Kernel TUN/TAP support ==&lt;br /&gt;
OpenVZ supports VPN inside a container via kernel TUN/TAP module and device.&lt;br /&gt;
To allow container #101 to use the TUN/TAP device the following should be done:&lt;br /&gt;
&lt;br /&gt;
Make sure the '''tun''' module has been already loaded on the [[hardware node]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# lsmod | grep tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it is not there, use the following command to load '''tun''' module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# modprobe tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also add it into /etc/modules.conf to make sure it will be loaded on every reboot automatically. (On RHEL create a script /etc/sysconfig/modules/tun.modules).&lt;br /&gt;
&lt;br /&gt;
== Granting container an access to TUN/TAP ==&lt;br /&gt;
Allow your container to use the tun/tap device by running the following commands on the host node:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --devices c:10:200:rw --save&lt;br /&gt;
 vzctl set 101 --capability net_admin:on --save&lt;br /&gt;
&lt;br /&gt;
And create the character device file inside the container (execute the following on the host node):&lt;br /&gt;
&lt;br /&gt;
 vzctl exec 101 mkdir -p /dev/net&lt;br /&gt;
 vzctl exec 101 mknod /dev/net/tun c 10 200&lt;br /&gt;
 vzctl exec 101 chmod 600 /dev/net/tun&lt;br /&gt;
&lt;br /&gt;
== Configuring VPN inside container ==&lt;br /&gt;
After the configuration steps above are done it is possible to use VPN software working with TUN/TAP inside&lt;br /&gt;
container just like on a usual standalone linux box.&lt;br /&gt;
&lt;br /&gt;
The following software can be used for VPN with TUN/TAP:&lt;br /&gt;
* Virtual TUNnel (http://vtun.sourceforge.net)&lt;br /&gt;
* OpenVPN (http://openvpn.sourceforge.net)&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
If NAT is needed within the VE, this error will occur on attempts to use NAT:&lt;br /&gt;
&lt;br /&gt;
 # iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j MASQUERADE&lt;br /&gt;
 iptables v1.4.3.2: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)&lt;br /&gt;
 Perhaps iptables or your kernel needs to be upgraded.&lt;br /&gt;
&lt;br /&gt;
The solution is given here:&lt;br /&gt;
&lt;br /&gt;
 http://kb.parallels.com/en/5228&lt;br /&gt;
&lt;br /&gt;
Also see page 69-70 of:&lt;br /&gt;
&lt;br /&gt;
 http://download.openvz.org/doc/OpenVZ-Users-Guide.pdf&lt;br /&gt;
&lt;br /&gt;
Note that the above steps do not solve the problem if a gentoo VE sits on a Centos HN; it's still an unsolved mystery.&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://vtun.sourceforge.net Virtual TUNnel]&lt;br /&gt;
* [http://openvpn.sourceforge.net OpenVPN]&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>Lithium</name></author>
		
	</entry>
</feed>