<?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=StalkR</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=StalkR"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/StalkR"/>
	<updated>2026-05-02T15:44:13Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Backup_of_a_running_container_with_vzdump&amp;diff=8628</id>
		<title>Backup of a running container with vzdump</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Backup_of_a_running_container_with_vzdump&amp;diff=8628"/>
		<updated>2010-05-20T03:02:23Z</updated>

		<summary type="html">&lt;p&gt;StalkR: /* Synopsis */ updated man page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Vzdump is a utility to make consistent snapshots of running OpenVZ containers (and KVM virtual machines if you are using [http://pve.proxmox.com Proxmox VE]). It basically creates a tar archive of the container's private area, which also includes the CT configuration files.&lt;br /&gt;
&lt;br /&gt;
There are several ways to provide consistency:&lt;br /&gt;
&lt;br /&gt;
* Stop the CT during backup (very long downtime)&lt;br /&gt;
* Use rsync and suspend/resume (minimal downtime)&lt;br /&gt;
* Use LVM2 (no downtime)&lt;br /&gt;
&lt;br /&gt;
Vzdump stores the backup on the disk in a single file. This file should go to a tape backup for archiving.&lt;br /&gt;
&lt;br /&gt;
== Download ==&lt;br /&gt;
Download vzdump rpm or deb packages from http://download.openvz.org/contrib/utils/vzdump/ or for newest version, check http://www.proxmox.com/cms_proxmox/en/technology/oss-software/openvz/&lt;br /&gt;
&lt;br /&gt;
For rpm based systems:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://www.proxmox.com/cms_proxmox/cms/upload/vzdump/vzdump-1.2-5.noarch.rpm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Debian based systems:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://www.proxmox.com/cms_proxmox/cms/upload/vzdump/vzdump_1.2-5_all.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
For rpm based systems:&lt;br /&gt;
&amp;lt;pre&amp;gt;rpm -i vzdump-1.2-5.noarch.rpm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Debian based systems:&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i vzdump_1.2-5_all.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Synopsis ==&lt;br /&gt;
&lt;br /&gt;
see also: &lt;br /&gt;
&amp;lt;pre&amp;gt;man vzdump&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzdump OPTIONS [--all | &amp;lt;VMID&amp;gt;]&lt;br /&gt;
       --exclude VMID          exclude VMID (assumes --all)&lt;br /&gt;
       --exclude-path REGEX    exclude certain files/directories. You&lt;br /&gt;
                               can use this option more than once to specify&lt;br /&gt;
                               multiple exclude paths&lt;br /&gt;
       --stdexcludes           exclude temporary files and logs&lt;br /&gt;
       --compress              compress dump file (gzip)&lt;br /&gt;
       --storage STORAGE_ID    store resulting files to STORAGE_ID (PVE only)&lt;br /&gt;
       --script                execute hook script&lt;br /&gt;
       --dumpdir DIR           store resulting files in DIR&lt;br /&gt;
       --maxfiles N            maximal number of backup files per VM.&lt;br /&gt;
       --tmpdir DIR            store temporary files in DIR. --suspend and --stop&lt;br /&gt;
                               are using this directory to store a copy of the VM.&lt;br /&gt;
       --mailto EMAIL          send notification mail to EMAIL. You can use&lt;br /&gt;
                               this option more than once to specify multiple&lt;br /&gt;
                               receivers&lt;br /&gt;
       --stop                  stop/start VM if running&lt;br /&gt;
       --suspend               suspend/resume VM when running&lt;br /&gt;
       --snapshot              use LVM snapshot when running&lt;br /&gt;
       --size MB               LVM snapshot size (default 1024)&lt;br /&gt;
       --bwlimit KBPS          limit I/O bandwidth; KBytes per second&lt;br /&gt;
       --lockwait MINUTES      maximal time to wait for the global&lt;br /&gt;
                               lock. vzdump uses a global lock file to make&lt;br /&gt;
                               sure that only one instance is running&lt;br /&gt;
                               (running several instance puts too much load&lt;br /&gt;
                               on a server). Default is 180 (3 hours).&lt;br /&gt;
       --stopwait MINUTES      maximal time to wait until a VM is stopped.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
Use a running container, for example install this: [[Proxmox Mail Gateway in container]].&lt;br /&gt;
&lt;br /&gt;
=== Backup ===&lt;br /&gt;
&lt;br /&gt;
Simply dump CT 777 — no snapshot, just archive the container private area and configuration files to the default dump directory (usually &amp;lt;code&amp;gt;/vz/dump/&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 vzdump 777&lt;br /&gt;
&lt;br /&gt;
Use rsync and suspend/resume to create a snapshot (minimal downtime).&lt;br /&gt;
&lt;br /&gt;
 vzdump --suspend 777&lt;br /&gt;
&lt;br /&gt;
Backup all containers and send notification mails to root.&lt;br /&gt;
&lt;br /&gt;
 vzdump --suspend --all --mailto root&lt;br /&gt;
&lt;br /&gt;
Use LVM2 to create snapshots (no downtime).&lt;br /&gt;
&lt;br /&gt;
 vzdump --dumpdir /space/backup --snapshot 777&lt;br /&gt;
&lt;br /&gt;
Note that using LVM2 and vzdump to create snapshots requires 512Mb of free space in your VG as described  [http://weblogs.amtex.nl/index.php?blog=2&amp;amp;title=using_vzdump_snapshot_to_backup_without_downtime&amp;amp;more=1&amp;amp;c=1&amp;amp;tb=1&amp;amp;pb=1 here].&lt;br /&gt;
&lt;br /&gt;
=== Restore ===&lt;br /&gt;
&lt;br /&gt;
Restore the above backup to CT 600:&lt;br /&gt;
&lt;br /&gt;
 vzrestore /space/backup/vzdump-777.tar 600&lt;br /&gt;
OR&lt;br /&gt;
 vzdump --restore /space/backup/vzdump-777.tar 600&lt;br /&gt;
&lt;br /&gt;
== Bugs ==&lt;br /&gt;
'''(not fixed in 1.2-4)'''&lt;br /&gt;
The rsync command used by vzdump to create the backup in suspend mode partially ignores the &amp;quot;--exclude-path&amp;quot; option.&lt;br /&gt;
In fact, even if the excluded paths won't appear in the final output, the whole VPS will be moved to the temporary directory, meaning that you need as much free disk space as your VPS size to use vzdump. It can be an issue in the case of a file server handling many files...&lt;br /&gt;
&lt;br /&gt;
''Workaround:'' A workaround has been proposed on OpenVZ forum, see below for the excerpt. (http://forum.openvz.org/index.php?t=msg&amp;amp;goto=36924&amp;amp;)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
User: tatawaki&lt;br /&gt;
Messages: 3&lt;br /&gt;
Registered: December 2008  Junior Member&lt;br /&gt;
From: *sbm.shawcable.net&lt;br /&gt;
&lt;br /&gt;
Line 694:&lt;br /&gt;
my $rsyncopts = &amp;quot;--stats --numeric-ids --bwlimit=${opt_bwlimit}&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# changes to&lt;br /&gt;
&lt;br /&gt;
my $rsyncopts = &amp;quot;--stats --numeric-ids --bwlimit=${opt_bwlimit}&amp;quot;;&lt;br /&gt;
$rsyncopts = $rsyncopts.&amp;quot; --exclude-from=/home/backups/exclude_vzdump.txt&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
the txt file contains &amp;lt;VEID&amp;gt;/home/:&lt;br /&gt;
&lt;br /&gt;
1094/home/&lt;br /&gt;
510/opt/&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''(fixed in 1.1-1)'''&lt;br /&gt;
vzdump will fail under Debian Etch in version 1.0-2 if it is invoked with parameter &amp;quot;--snapshot&amp;quot; and if the logical volume name contains a hyphen.&lt;br /&gt;
&lt;br /&gt;
''Workaround:'' One possible workaround is to rename the logical volume in question thus it doesn't contain any hyphen.&lt;br /&gt;
A bug report was sent to proxmox on 02 June 2008.&lt;br /&gt;
Other distributions or versions may be affected, too.&lt;br /&gt;
&lt;br /&gt;
== Hooks ==&lt;br /&gt;
&lt;br /&gt;
http://nachtmann.it/blog/vzdump-hook-ftp-backup-script - Backup to FTP with limited capacity&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>StalkR</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Backup_of_a_running_container_with_vzdump&amp;diff=8627</id>
		<title>Backup of a running container with vzdump</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Backup_of_a_running_container_with_vzdump&amp;diff=8627"/>
		<updated>2010-05-20T03:00:26Z</updated>

		<summary type="html">&lt;p&gt;StalkR: /* Installation */ updated names for version 1.2-5&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Vzdump is a utility to make consistent snapshots of running OpenVZ containers (and KVM virtual machines if you are using [http://pve.proxmox.com Proxmox VE]). It basically creates a tar archive of the container's private area, which also includes the CT configuration files.&lt;br /&gt;
&lt;br /&gt;
There are several ways to provide consistency:&lt;br /&gt;
&lt;br /&gt;
* Stop the CT during backup (very long downtime)&lt;br /&gt;
* Use rsync and suspend/resume (minimal downtime)&lt;br /&gt;
* Use LVM2 (no downtime)&lt;br /&gt;
&lt;br /&gt;
Vzdump stores the backup on the disk in a single file. This file should go to a tape backup for archiving.&lt;br /&gt;
&lt;br /&gt;
== Download ==&lt;br /&gt;
Download vzdump rpm or deb packages from http://download.openvz.org/contrib/utils/vzdump/ or for newest version, check http://www.proxmox.com/cms_proxmox/en/technology/oss-software/openvz/&lt;br /&gt;
&lt;br /&gt;
For rpm based systems:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://www.proxmox.com/cms_proxmox/cms/upload/vzdump/vzdump-1.2-5.noarch.rpm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Debian based systems:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://www.proxmox.com/cms_proxmox/cms/upload/vzdump/vzdump_1.2-5_all.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
For rpm based systems:&lt;br /&gt;
&amp;lt;pre&amp;gt;rpm -i vzdump-1.2-5.noarch.rpm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Debian based systems:&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i vzdump_1.2-5_all.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Synopsis ==&lt;br /&gt;
&lt;br /&gt;
see also: &lt;br /&gt;
&amp;lt;pre&amp;gt;man vzdump&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzdump OPTIONS [--all | &amp;lt;VMID&amp;gt;]&lt;br /&gt;
&lt;br /&gt;
       --exclude VPSID         exclude VPSID (assumes --all)&lt;br /&gt;
       --exclude-path REGEX    exclude certain files/directories. You&lt;br /&gt;
                               can use this option more than once to specify&lt;br /&gt;
                               multiple exclude paths&lt;br /&gt;
       --stdexcludes           exclude temorary files and logs&lt;br /&gt;
       --compress              compress dump file (gzip)&lt;br /&gt;
       --dumpdir DIR           store resulting files in DIR&lt;br /&gt;
       --tmpdir DIR            store temporary files in DIR. --suspend and --stop are using this directory to store a copy of the VM.&lt;br /&gt;
       --mailto EMAIL          send notification mail to EMAIL. You can use&lt;br /&gt;
                               this option more than once to specify multiple&lt;br /&gt;
                               receivers&lt;br /&gt;
       --stop                  stop/start VPS if running&lt;br /&gt;
       --suspend               suspend/resume VPS when running&lt;br /&gt;
       --snapshot              use LVM snapshot when running&lt;br /&gt;
       --size MB               LVM snapshot size (default 1024)&lt;br /&gt;
       --bwlimit KBPS          limit I/O bandwidth; KBytes per second&lt;br /&gt;
       --lockwait MINUTES      maximal time to wait for the global&lt;br /&gt;
                               lock. vzdump uses a global lock file to make&lt;br /&gt;
                               sure that only one instance is running&lt;br /&gt;
                               (running sereral instance puts too much load&lt;br /&gt;
                               on a server). Default is 180 (3 hours).&lt;br /&gt;
       --stopwait MINUTES      maximal time to wait until a VM is stopped.&lt;br /&gt;
       --restore FILENAME      restore FILENAME&lt;br /&gt;
 &lt;br /&gt;
== Examples ==&lt;br /&gt;
Use a running container, for example install this: [[Proxmox Mail Gateway in container]].&lt;br /&gt;
&lt;br /&gt;
=== Backup ===&lt;br /&gt;
&lt;br /&gt;
Simply dump CT 777 — no snapshot, just archive the container private area and configuration files to the default dump directory (usually &amp;lt;code&amp;gt;/vz/dump/&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 vzdump 777&lt;br /&gt;
&lt;br /&gt;
Use rsync and suspend/resume to create a snapshot (minimal downtime).&lt;br /&gt;
&lt;br /&gt;
 vzdump --suspend 777&lt;br /&gt;
&lt;br /&gt;
Backup all containers and send notification mails to root.&lt;br /&gt;
&lt;br /&gt;
 vzdump --suspend --all --mailto root&lt;br /&gt;
&lt;br /&gt;
Use LVM2 to create snapshots (no downtime).&lt;br /&gt;
&lt;br /&gt;
 vzdump --dumpdir /space/backup --snapshot 777&lt;br /&gt;
&lt;br /&gt;
Note that using LVM2 and vzdump to create snapshots requires 512Mb of free space in your VG as described  [http://weblogs.amtex.nl/index.php?blog=2&amp;amp;title=using_vzdump_snapshot_to_backup_without_downtime&amp;amp;more=1&amp;amp;c=1&amp;amp;tb=1&amp;amp;pb=1 here].&lt;br /&gt;
&lt;br /&gt;
=== Restore ===&lt;br /&gt;
&lt;br /&gt;
Restore the above backup to CT 600:&lt;br /&gt;
&lt;br /&gt;
 vzrestore /space/backup/vzdump-777.tar 600&lt;br /&gt;
OR&lt;br /&gt;
 vzdump --restore /space/backup/vzdump-777.tar 600&lt;br /&gt;
&lt;br /&gt;
== Bugs ==&lt;br /&gt;
'''(not fixed in 1.2-4)'''&lt;br /&gt;
The rsync command used by vzdump to create the backup in suspend mode partially ignores the &amp;quot;--exclude-path&amp;quot; option.&lt;br /&gt;
In fact, even if the excluded paths won't appear in the final output, the whole VPS will be moved to the temporary directory, meaning that you need as much free disk space as your VPS size to use vzdump. It can be an issue in the case of a file server handling many files...&lt;br /&gt;
&lt;br /&gt;
''Workaround:'' A workaround has been proposed on OpenVZ forum, see below for the excerpt. (http://forum.openvz.org/index.php?t=msg&amp;amp;goto=36924&amp;amp;)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
User: tatawaki&lt;br /&gt;
Messages: 3&lt;br /&gt;
Registered: December 2008  Junior Member&lt;br /&gt;
From: *sbm.shawcable.net&lt;br /&gt;
&lt;br /&gt;
Line 694:&lt;br /&gt;
my $rsyncopts = &amp;quot;--stats --numeric-ids --bwlimit=${opt_bwlimit}&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# changes to&lt;br /&gt;
&lt;br /&gt;
my $rsyncopts = &amp;quot;--stats --numeric-ids --bwlimit=${opt_bwlimit}&amp;quot;;&lt;br /&gt;
$rsyncopts = $rsyncopts.&amp;quot; --exclude-from=/home/backups/exclude_vzdump.txt&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
the txt file contains &amp;lt;VEID&amp;gt;/home/:&lt;br /&gt;
&lt;br /&gt;
1094/home/&lt;br /&gt;
510/opt/&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''(fixed in 1.1-1)'''&lt;br /&gt;
vzdump will fail under Debian Etch in version 1.0-2 if it is invoked with parameter &amp;quot;--snapshot&amp;quot; and if the logical volume name contains a hyphen.&lt;br /&gt;
&lt;br /&gt;
''Workaround:'' One possible workaround is to rename the logical volume in question thus it doesn't contain any hyphen.&lt;br /&gt;
A bug report was sent to proxmox on 02 June 2008.&lt;br /&gt;
Other distributions or versions may be affected, too.&lt;br /&gt;
&lt;br /&gt;
== Hooks ==&lt;br /&gt;
&lt;br /&gt;
http://nachtmann.it/blog/vzdump-hook-ftp-backup-script - Backup to FTP with limited capacity&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>StalkR</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Backup_of_a_running_container_with_vzdump&amp;diff=8626</id>
		<title>Backup of a running container with vzdump</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Backup_of_a_running_container_with_vzdump&amp;diff=8626"/>
		<updated>2010-05-20T02:59:54Z</updated>

		<summary type="html">&lt;p&gt;StalkR: /* Download */ updated links to vzdump version 1.2-5&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Vzdump is a utility to make consistent snapshots of running OpenVZ containers (and KVM virtual machines if you are using [http://pve.proxmox.com Proxmox VE]). It basically creates a tar archive of the container's private area, which also includes the CT configuration files.&lt;br /&gt;
&lt;br /&gt;
There are several ways to provide consistency:&lt;br /&gt;
&lt;br /&gt;
* Stop the CT during backup (very long downtime)&lt;br /&gt;
* Use rsync and suspend/resume (minimal downtime)&lt;br /&gt;
* Use LVM2 (no downtime)&lt;br /&gt;
&lt;br /&gt;
Vzdump stores the backup on the disk in a single file. This file should go to a tape backup for archiving.&lt;br /&gt;
&lt;br /&gt;
== Download ==&lt;br /&gt;
Download vzdump rpm or deb packages from http://download.openvz.org/contrib/utils/vzdump/ or for newest version, check http://www.proxmox.com/cms_proxmox/en/technology/oss-software/openvz/&lt;br /&gt;
&lt;br /&gt;
For rpm based systems:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://www.proxmox.com/cms_proxmox/cms/upload/vzdump/vzdump-1.2-5.noarch.rpm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Debian based systems:&lt;br /&gt;
&amp;lt;pre&amp;gt;wget http://www.proxmox.com/cms_proxmox/cms/upload/vzdump/vzdump_1.2-5_all.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
For rpm based systems:&lt;br /&gt;
&amp;lt;pre&amp;gt;rpm -i vzdump-1.1-2.noarch.rpm&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For Debian based systems:&lt;br /&gt;
&amp;lt;pre&amp;gt;dpkg -i vzdump_1.1-2_all.deb&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Synopsis ==&lt;br /&gt;
&lt;br /&gt;
see also: &lt;br /&gt;
&amp;lt;pre&amp;gt;man vzdump&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
vzdump OPTIONS [--all | &amp;lt;VMID&amp;gt;]&lt;br /&gt;
&lt;br /&gt;
       --exclude VPSID         exclude VPSID (assumes --all)&lt;br /&gt;
       --exclude-path REGEX    exclude certain files/directories. You&lt;br /&gt;
                               can use this option more than once to specify&lt;br /&gt;
                               multiple exclude paths&lt;br /&gt;
       --stdexcludes           exclude temorary files and logs&lt;br /&gt;
       --compress              compress dump file (gzip)&lt;br /&gt;
       --dumpdir DIR           store resulting files in DIR&lt;br /&gt;
       --tmpdir DIR            store temporary files in DIR. --suspend and --stop are using this directory to store a copy of the VM.&lt;br /&gt;
       --mailto EMAIL          send notification mail to EMAIL. You can use&lt;br /&gt;
                               this option more than once to specify multiple&lt;br /&gt;
                               receivers&lt;br /&gt;
       --stop                  stop/start VPS if running&lt;br /&gt;
       --suspend               suspend/resume VPS when running&lt;br /&gt;
       --snapshot              use LVM snapshot when running&lt;br /&gt;
       --size MB               LVM snapshot size (default 1024)&lt;br /&gt;
       --bwlimit KBPS          limit I/O bandwidth; KBytes per second&lt;br /&gt;
       --lockwait MINUTES      maximal time to wait for the global&lt;br /&gt;
                               lock. vzdump uses a global lock file to make&lt;br /&gt;
                               sure that only one instance is running&lt;br /&gt;
                               (running sereral instance puts too much load&lt;br /&gt;
                               on a server). Default is 180 (3 hours).&lt;br /&gt;
       --stopwait MINUTES      maximal time to wait until a VM is stopped.&lt;br /&gt;
       --restore FILENAME      restore FILENAME&lt;br /&gt;
 &lt;br /&gt;
== Examples ==&lt;br /&gt;
Use a running container, for example install this: [[Proxmox Mail Gateway in container]].&lt;br /&gt;
&lt;br /&gt;
=== Backup ===&lt;br /&gt;
&lt;br /&gt;
Simply dump CT 777 — no snapshot, just archive the container private area and configuration files to the default dump directory (usually &amp;lt;code&amp;gt;/vz/dump/&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
 vzdump 777&lt;br /&gt;
&lt;br /&gt;
Use rsync and suspend/resume to create a snapshot (minimal downtime).&lt;br /&gt;
&lt;br /&gt;
 vzdump --suspend 777&lt;br /&gt;
&lt;br /&gt;
Backup all containers and send notification mails to root.&lt;br /&gt;
&lt;br /&gt;
 vzdump --suspend --all --mailto root&lt;br /&gt;
&lt;br /&gt;
Use LVM2 to create snapshots (no downtime).&lt;br /&gt;
&lt;br /&gt;
 vzdump --dumpdir /space/backup --snapshot 777&lt;br /&gt;
&lt;br /&gt;
Note that using LVM2 and vzdump to create snapshots requires 512Mb of free space in your VG as described  [http://weblogs.amtex.nl/index.php?blog=2&amp;amp;title=using_vzdump_snapshot_to_backup_without_downtime&amp;amp;more=1&amp;amp;c=1&amp;amp;tb=1&amp;amp;pb=1 here].&lt;br /&gt;
&lt;br /&gt;
=== Restore ===&lt;br /&gt;
&lt;br /&gt;
Restore the above backup to CT 600:&lt;br /&gt;
&lt;br /&gt;
 vzrestore /space/backup/vzdump-777.tar 600&lt;br /&gt;
OR&lt;br /&gt;
 vzdump --restore /space/backup/vzdump-777.tar 600&lt;br /&gt;
&lt;br /&gt;
== Bugs ==&lt;br /&gt;
'''(not fixed in 1.2-4)'''&lt;br /&gt;
The rsync command used by vzdump to create the backup in suspend mode partially ignores the &amp;quot;--exclude-path&amp;quot; option.&lt;br /&gt;
In fact, even if the excluded paths won't appear in the final output, the whole VPS will be moved to the temporary directory, meaning that you need as much free disk space as your VPS size to use vzdump. It can be an issue in the case of a file server handling many files...&lt;br /&gt;
&lt;br /&gt;
''Workaround:'' A workaround has been proposed on OpenVZ forum, see below for the excerpt. (http://forum.openvz.org/index.php?t=msg&amp;amp;goto=36924&amp;amp;)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
User: tatawaki&lt;br /&gt;
Messages: 3&lt;br /&gt;
Registered: December 2008  Junior Member&lt;br /&gt;
From: *sbm.shawcable.net&lt;br /&gt;
&lt;br /&gt;
Line 694:&lt;br /&gt;
my $rsyncopts = &amp;quot;--stats --numeric-ids --bwlimit=${opt_bwlimit}&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
# changes to&lt;br /&gt;
&lt;br /&gt;
my $rsyncopts = &amp;quot;--stats --numeric-ids --bwlimit=${opt_bwlimit}&amp;quot;;&lt;br /&gt;
$rsyncopts = $rsyncopts.&amp;quot; --exclude-from=/home/backups/exclude_vzdump.txt&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
the txt file contains &amp;lt;VEID&amp;gt;/home/:&lt;br /&gt;
&lt;br /&gt;
1094/home/&lt;br /&gt;
510/opt/&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''(fixed in 1.1-1)'''&lt;br /&gt;
vzdump will fail under Debian Etch in version 1.0-2 if it is invoked with parameter &amp;quot;--snapshot&amp;quot; and if the logical volume name contains a hyphen.&lt;br /&gt;
&lt;br /&gt;
''Workaround:'' One possible workaround is to rename the logical volume in question thus it doesn't contain any hyphen.&lt;br /&gt;
A bug report was sent to proxmox on 02 June 2008.&lt;br /&gt;
Other distributions or versions may be affected, too.&lt;br /&gt;
&lt;br /&gt;
== Hooks ==&lt;br /&gt;
&lt;br /&gt;
http://nachtmann.it/blog/vzdump-hook-ftp-backup-script - Backup to FTP with limited capacity&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;/div&gt;</summary>
		<author><name>StalkR</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Debian_template_creation&amp;diff=7529</id>
		<title>Debian template creation</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Debian_template_creation&amp;diff=7529"/>
		<updated>2009-09-17T06:16:39Z</updated>

		<summary type="html">&lt;p&gt;StalkR: /* Preparing for and packing template cache */ remove /etc/hostname file before packing template&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;These are rough instructions of how to manually create basic Debian Etch (4.0) template cache, which can be used to create OpenVZ [[VE]]s based on Debian Etch (4.0). (see also &amp;lt;tt&amp;gt;/usr/share/doc/vzctl/README.Debian&amp;lt;/tt&amp;gt; in the ''vzctl'' Debian package)&lt;br /&gt;
&lt;br /&gt;
'''Notes:'''&lt;br /&gt;
* You shouldn't be running as root, but as a user that is permitted to use sudo instead.  It's a dangerous idea, run as root at your peril.&lt;br /&gt;
* Anywhere you see &amp;lt;tt&amp;gt;/vz&amp;lt;/tt&amp;gt;, you might really need to use &amp;lt;tt&amp;gt;/var/lib/vz&amp;lt;/tt&amp;gt; instead, especially on a Debian Etch host.&lt;br /&gt;
* Anywhere you see &amp;lt;tt&amp;gt;http://http.us.debian.org/debian/&amp;lt;/tt&amp;gt;, you can substitute your favorite Debian mirror.  ([http://www.debian.org/mirror/list List of official Debian Mirrors])&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
You need to have a working copy of &amp;lt;tt&amp;gt;debootstrap&amp;lt;/tt&amp;gt; running on your hardware node.&lt;br /&gt;
&lt;br /&gt;
For Debian:&lt;br /&gt;
 sudo apt-get install debootstrap&lt;br /&gt;
&lt;br /&gt;
For Gentoo:&lt;br /&gt;
 sudo emerge debootstrap&lt;br /&gt;
&lt;br /&gt;
For Fedora (at least Fedora 8 have it, not sure about earlier versions):&lt;br /&gt;
 sudo yum install debootstrap&lt;br /&gt;
&lt;br /&gt;
For other distros you might need to install it from sources, or search for an appropriate package for your distribution.  An RPM is available on the [http://forum.openvz.org/index.php?t=tree&amp;amp;th=142&amp;amp;mid=584 OpenVZ Forum].&lt;br /&gt;
&lt;br /&gt;
== Bootstrapping Debian ==&lt;br /&gt;
&lt;br /&gt;
You can install different releases of Debian into a VE's private directory using the debootstrap command.&lt;br /&gt;
&lt;br /&gt;
The command parameters are:&lt;br /&gt;
&lt;br /&gt;
  debootstrap --arch ARCH NAME DIRECTORY URL&lt;br /&gt;
&lt;br /&gt;
Specify your architecture instead of &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; if you're using something other than i386/x86.  For example, for AMD64/x86_64, use &amp;lt;tt&amp;gt;amd64&amp;lt;/tt&amp;gt; or for ia64, use &amp;lt;tt&amp;gt;ia64&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We use VE ID of 777 for this example; surely it can be any other unused ID.&lt;br /&gt;
&lt;br /&gt;
=== Etch (current Debian stable) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap --arch i386 etch /vz/private/777 http://http.us.debian.org/debian/&lt;br /&gt;
&lt;br /&gt;
=== Sarge (old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap sarge /vz/private/777 http://http.us.debian.org/debian&lt;br /&gt;
&lt;br /&gt;
=== Woody (very old release) ===&lt;br /&gt;
&lt;br /&gt;
 debootstrap woody /vz/private/777 http://archive.debian.org/&lt;br /&gt;
&lt;br /&gt;
== Preparing and starting the VE ==&lt;br /&gt;
&lt;br /&gt;
=== Setting VE config ===&lt;br /&gt;
First, we need a config for the [[VE]]:&lt;br /&gt;
 sudo vzctl set 777 --applyconfig vps.basic --save&lt;br /&gt;
&lt;br /&gt;
=== Setting VE OSTEMPLATE ===&lt;br /&gt;
Also, we need &amp;lt;tt&amp;gt;OSTEMPLATE&amp;lt;/tt&amp;gt; to be set in VE configuration file, for the [[vzctl]] to work properly.&lt;br /&gt;
&lt;br /&gt;
 sudo sh -c 'echo &amp;quot;OSTEMPLATE=debian-4.0&amp;quot; &amp;gt;&amp;gt; /etc/vz/conf/777.conf'&lt;br /&gt;
&lt;br /&gt;
=== Setting VE IP address ===&lt;br /&gt;
For the [[VE]] to be able to download updates from the Internet, we need a valid IP address for it:&lt;br /&gt;
 sudo vzctl set 777 --ipadd x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
{{Note|if you use private IP for the VE, you have to set up NAT as described in [[Using NAT for VE with private IPs]].}}&lt;br /&gt;
&lt;br /&gt;
=== Setting DNS server for VE ===&lt;br /&gt;
For the [[VE]] to be able to download updates from the Internet, we also need to specify a DNS for it:&lt;br /&gt;
 sudo vzctl set 777 --nameserver x.x.x.x --save&lt;br /&gt;
&lt;br /&gt;
=== Starting VE ===&lt;br /&gt;
Now start the VE:&lt;br /&gt;
 sudo vzctl start 777&lt;br /&gt;
&lt;br /&gt;
== Customizing the installation ==&lt;br /&gt;
A few things need to be done inside a newly created VE for it to become suitable for OpenVZ.  All those things are done inside the VE, so first command is:&lt;br /&gt;
 sudo vzctl enter 777&lt;br /&gt;
 export PATH=/sbin:/usr/sbin:/bin:/usr/bin&lt;br /&gt;
&lt;br /&gt;
{{Warning|Do not run the commands below on the hardware node, they are only to be run within the VE!}}&lt;br /&gt;
&lt;br /&gt;
=== Set Debian repositories ===&lt;br /&gt;
 cat &amp;lt;&amp;lt;EOF &amp;gt; /etc/apt/sources.list&lt;br /&gt;
 deb http://http.us.debian.org/debian etch main contrib&lt;br /&gt;
 deb http://security.debian.org etch/updates main contrib&lt;br /&gt;
 EOF&lt;br /&gt;
&lt;br /&gt;
=== Get new security updates ===&lt;br /&gt;
 apt-get update&lt;br /&gt;
 apt-get upgrade&lt;br /&gt;
&lt;br /&gt;
=== Install some more packages ===&lt;br /&gt;
Installing packages could be an interactive process so the system might ask some questions.  You can install more packages if you'd like.  For example:&lt;br /&gt;
 apt-get install ssh quota&lt;br /&gt;
&lt;br /&gt;
=== Set sane permissions for &amp;lt;tt&amp;gt;/root&amp;lt;/tt&amp;gt; directory ===&lt;br /&gt;
 chmod 700 /root&lt;br /&gt;
&lt;br /&gt;
=== Disable root login ===&lt;br /&gt;
This will disable root login by default.&lt;br /&gt;
 usermod -L root&lt;br /&gt;
&lt;br /&gt;
=== Disable getty ===&lt;br /&gt;
Disable running &amp;lt;tt&amp;gt;getty&amp;lt;/tt&amp;gt;s on terminals as a VE does not have any:&lt;br /&gt;
 sed -i -e '/getty/d' /etc/inittab&lt;br /&gt;
&lt;br /&gt;
=== Disable &amp;lt;tt&amp;gt;sync()&amp;lt;/tt&amp;gt; for syslog ===&lt;br /&gt;
Turn off doing &amp;lt;tt&amp;gt;sync()&amp;lt;/tt&amp;gt; on every write for &amp;lt;tt&amp;gt;syslog&amp;lt;/tt&amp;gt;'s log files, to improve I/O performance:&lt;br /&gt;
 &amp;lt;pre&amp;gt;sed -i -e 's@\([[:space:]]\)\(/var/log/\)@\1-\2@' /etc/*syslog.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Fix &amp;lt;tt&amp;gt;/etc/mtab&amp;lt;/tt&amp;gt; ===&lt;br /&gt;
Link &amp;lt;tt&amp;gt;/etc/mtab&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;/proc/mounts&amp;lt;/tt&amp;gt;, so &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt; and friends will work:&lt;br /&gt;
 rm -f /etc/mtab&lt;br /&gt;
 ln -s /proc/mounts /etc/mtab&lt;br /&gt;
&lt;br /&gt;
=== Remove some unneeded packages ===&lt;br /&gt;
If you have any packages you'd like to remove, now's the time for it.  Here's an example:&lt;br /&gt;
 dpkg --purge modutils ppp pppoeconf pppoe pppconfig&lt;br /&gt;
&lt;br /&gt;
=== Disable services ===&lt;br /&gt;
Do not start some services, stick to bare minimum:&lt;br /&gt;
 update-rc.d -f klogd remove&lt;br /&gt;
 update-rc.d -f quotarpc remove&lt;br /&gt;
 update-rc.d -f exim4 remove&lt;br /&gt;
 update-rc.d -f inetd remove&lt;br /&gt;
&lt;br /&gt;
=== Fix SSH host keys ===&lt;br /&gt;
This is only useful if you installed SSH.  Each individual [[VE]] should have its own pair of SSH host keys.  The code below will wipe out the existing SSH keys and instruct the newly-created [[VE]] to create new SSH keys on first boot.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- please do not remove &amp;lt;source&amp;gt;...&amp;lt;/source&amp;gt; pair of tags below,&lt;br /&gt;
     otherwise quotes after -N (-N '') are not visible --&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
rm -f /etc/ssh/ssh_host_*&lt;br /&gt;
cat &amp;lt;&amp;lt; EOF &amp;gt; /etc/rc2.d/S15ssh_gen_host_keys&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -t rsa -N ''&lt;br /&gt;
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -t dsa -N ''&lt;br /&gt;
rm -f \$0&lt;br /&gt;
EOF&lt;br /&gt;
chmod a+x /etc/rc2.d/S15ssh_gen_host_keys&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Clean packages ===&lt;br /&gt;
After installing packages, you'll have some junk packages laying around in your cache.  Since you don't want your template to have those, this command will wipe them out.&lt;br /&gt;
 apt-get clean&lt;br /&gt;
&lt;br /&gt;
Now everything is done.  Exit from the template and go back to the hardware node.&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
== Preparing for and packing template cache ==&lt;br /&gt;
&lt;br /&gt;
We don't need an IP for the VE anymore, and we definitely do not need it in template cache, so remove it:&lt;br /&gt;
 sudo vzctl set 777 --ipdel all --save&lt;br /&gt;
&lt;br /&gt;
Also, remove DNS server and search domain information from ''/etc/resolv.conf'' file '''in VE''':&lt;br /&gt;
 sudo nano /vz/private/777/etc/resolv.conf&lt;br /&gt;
&lt;br /&gt;
Also, remove ''/etc/hostname'' file '''in VE''':&lt;br /&gt;
 sudo rm -f /vz/private/777/etc/hostname&lt;br /&gt;
&lt;br /&gt;
Stop the VE:&lt;br /&gt;
 sudo vzctl stop 777&lt;br /&gt;
&lt;br /&gt;
Go to the VE directory:&lt;br /&gt;
 cd /vz/private/777&lt;br /&gt;
&lt;br /&gt;
Now create a cached OS tarball.  In the command below, you'll want to replace &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; with your architecture (i386, amd64, ia64, etc).&lt;br /&gt;
 sudo tar -zcf /vz/template/cache/debian-4.0-i386-minimal.tar.gz .&lt;br /&gt;
&lt;br /&gt;
Look at the resulting tarball to see its size is sane:&lt;br /&gt;
 # ls -lh /vz/template/cache&lt;br /&gt;
 -rw-r--r--  1 root root  51M Apr 10 03:16 debian-4.0-i386-minimal.tar.gz&lt;br /&gt;
&lt;br /&gt;
== Checking if template cache works ==&lt;br /&gt;
We can now create a VE based on the just-created template cache.  Be sure to change &amp;lt;tt&amp;gt;i386&amp;lt;/tt&amp;gt; to your architecture just like you did when you named the tarball above.&lt;br /&gt;
 sudo vzctl create 123456 --ostemplate debian-4.0-i386-minimal&lt;br /&gt;
&lt;br /&gt;
Now make sure that it works:&lt;br /&gt;
 sudo vzctl start 123456&lt;br /&gt;
 sudo vzctl exec 123456 ps ax&lt;br /&gt;
&lt;br /&gt;
You should see that a few processes are running.&lt;br /&gt;
&lt;br /&gt;
== Final cleanup ==&lt;br /&gt;
Stop and remove the test VE you just created:&lt;br /&gt;
 sudo vzctl stop 123456&lt;br /&gt;
 sudo vzctl destroy 123456&lt;br /&gt;
 sudo rm /etc/vz/conf/123456.conf.destroyed&lt;br /&gt;
&lt;br /&gt;
Finally, let's remove the VE we used for OS template cache creation:&lt;br /&gt;
 sudo vzctl destroy 777&lt;br /&gt;
 sudo rm /etc/vz/conf/777.conf.destroyed&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Templates]]&lt;br /&gt;
[[Category: Debian]]&lt;/div&gt;</summary>
		<author><name>StalkR</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_Ethernet_device&amp;diff=7526</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=7526"/>
		<updated>2009-09-12T00:36:17Z</updated>

		<summary type="html">&lt;p&gt;StalkR: /* Configure device and add route in CT0 */ add -&amp;gt; adds&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;
Assuming you have 192.168.0.0/24 on your LAN, you will learn how to integrate a container in this LAN using veth.&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 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;
=== Using a directly routed IPv4 with virtual Ethernet device ===&lt;br /&gt;
&lt;br /&gt;
==== Situation ====&lt;br /&gt;
Hardware Node (HN/CT0) has 192.168.0.1/24 with router 192.168.0.254.&lt;br /&gt;
&lt;br /&gt;
We also know that IPv4 10.0.0.1/32 is directly routed to 192.168.0.1 (this is called a ''fail-over IP'').&lt;br /&gt;
&lt;br /&gt;
We want to give this directly routed IPv4 address to a container (CT).&lt;br /&gt;
&lt;br /&gt;
==== Start container ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl start 101&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 device and add route in CT0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ifconfig veth101.0 0&lt;br /&gt;
[host-node]# ip route add 10.0.0.1 dev veth101.0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can automatize this at VPS creation by using a mount script &amp;lt;tt&amp;gt;$VEID.mount&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The problem here is that the ''veth'' interface appears in CT0 '''after''' VPS has started, therefore we cannot directly use the commands in the mount script. We launch a shell script (enclosed by { }) in background (operator '''&amp;amp;''') that waits for the interface to be ready and then adds the IP route.&lt;br /&gt;
&lt;br /&gt;
Contents of the mount script &amp;lt;tt&amp;gt;/etc/vz/conf/101.mount&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# This script source VPS configuration files in the same order as vzctl does&lt;br /&gt;
&lt;br /&gt;
# if one of these files does not exist then something is really broken&lt;br /&gt;
[ -f /etc/vz/vz.conf ] || exit 1&lt;br /&gt;
[ -f $VE_CONFFILE ] || exit 1&lt;br /&gt;
&lt;br /&gt;
# source both files. Note the order, it is important&lt;br /&gt;
. /etc/vz/vz.conf&lt;br /&gt;
. $VE_CONFFILE&lt;br /&gt;
&lt;br /&gt;
# Configure veth with IP after VPS has started&lt;br /&gt;
{&lt;br /&gt;
  IP=X.Y.Z.T&lt;br /&gt;
  DEV=veth101.0&lt;br /&gt;
  while sleep 1; do&lt;br /&gt;
    /sbin/ifconfig $DEV 0 &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    if [ $? -eq 0 ]; then&lt;br /&gt;
      /sbin/ip route add $IP dev $DEV&lt;br /&gt;
      break&lt;br /&gt;
    fi&lt;br /&gt;
  done&lt;br /&gt;
} &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Make sure IPv4 forwarding is enabled in CT0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/ip_forward&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/veth101.0/forwarding&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can permanently set this by using &amp;lt;tt&amp;gt;/etc/sysctl.conf&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Configure device in CT ====&lt;br /&gt;
&lt;br /&gt;
1. Configure IP address&lt;br /&gt;
&lt;br /&gt;
2. Add gateway&lt;br /&gt;
&lt;br /&gt;
3. Add default route&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[ve-101]# /sbin/ifconfig eth0 10.0.0.1 netmask 255.255.255.255&lt;br /&gt;
[ve-101]# /sbin/ip route add 192.168.0.1 dev eth0&lt;br /&gt;
[ve-101]# /sbin/ip route default via 192.168.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In a Debian container, you can configure this permanently by using &amp;lt;tt&amp;gt;/etc/network/interfaces&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
auto eth0&lt;br /&gt;
iface eth0 inet static&lt;br /&gt;
        address 10.0.0.1&lt;br /&gt;
        netmask 255.255.255.255&lt;br /&gt;
        up /sbin/ip route add 192.168.0.1 dev eth0&lt;br /&gt;
        up /sbin/ip route add default via 192.168.0.1&lt;br /&gt;
&amp;lt;/pre&amp;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>StalkR</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_Ethernet_device&amp;diff=7525</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=7525"/>
		<updated>2009-09-12T00:21:22Z</updated>

		<summary type="html">&lt;p&gt;StalkR: /* Configure device and add route in CT0 */ adding script to automatize route creation + new subsection to make sure ipv4 forwarding is enabled in CT0&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;
Assuming you have 192.168.0.0/24 on your LAN, you will learn how to integrate a container in this LAN using veth.&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 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;
=== Using a directly routed IPv4 with virtual Ethernet device ===&lt;br /&gt;
&lt;br /&gt;
==== Situation ====&lt;br /&gt;
Hardware Node (HN/CT0) has 192.168.0.1/24 with router 192.168.0.254.&lt;br /&gt;
&lt;br /&gt;
We also know that IPv4 10.0.0.1/32 is directly routed to 192.168.0.1 (this is called a ''fail-over IP'').&lt;br /&gt;
&lt;br /&gt;
We want to give this directly routed IPv4 address to a container (CT).&lt;br /&gt;
&lt;br /&gt;
==== Start container ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl start 101&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 device and add route in CT0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ifconfig veth101.0 0&lt;br /&gt;
[host-node]# ip route add 10.0.0.1 dev veth101.0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can automatize this at VPS creation by using a mount script &amp;lt;tt&amp;gt;$VEID.mount&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The problem here is that the ''veth'' interface appears in CT0 '''after''' VPS has started, therefore we cannot directly use the commands in the mount script. We launch a shell script (enclosed by { }) in background (operator '''&amp;amp;''') that waits for the interface to be ready and then add the IP route.&lt;br /&gt;
&lt;br /&gt;
Contents of the mount script &amp;lt;tt&amp;gt;/etc/vz/conf/101.mount&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# This script source VPS configuration files in the same order as vzctl does&lt;br /&gt;
&lt;br /&gt;
# if one of these files does not exist then something is really broken&lt;br /&gt;
[ -f /etc/vz/vz.conf ] || exit 1&lt;br /&gt;
[ -f $VE_CONFFILE ] || exit 1&lt;br /&gt;
&lt;br /&gt;
# source both files. Note the order, it is important&lt;br /&gt;
. /etc/vz/vz.conf&lt;br /&gt;
. $VE_CONFFILE&lt;br /&gt;
&lt;br /&gt;
# Configure veth with IP after VPS has started&lt;br /&gt;
{&lt;br /&gt;
  IP=X.Y.Z.T&lt;br /&gt;
  DEV=veth101.0&lt;br /&gt;
  while sleep 1; do&lt;br /&gt;
    /sbin/ifconfig $DEV 0 &amp;gt;/dev/null 2&amp;gt;&amp;amp;1&lt;br /&gt;
    if [ $? -eq 0 ]; then&lt;br /&gt;
      /sbin/ip route add $IP dev $DEV&lt;br /&gt;
      break&lt;br /&gt;
    fi&lt;br /&gt;
  done&lt;br /&gt;
} &amp;amp;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Make sure IPv4 forwarding is enabled in CT0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/ip_forward&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/veth101.0/forwarding&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can permanently set this by using &amp;lt;tt&amp;gt;/etc/sysctl.conf&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Configure device in CT ====&lt;br /&gt;
&lt;br /&gt;
1. Configure IP address&lt;br /&gt;
&lt;br /&gt;
2. Add gateway&lt;br /&gt;
&lt;br /&gt;
3. Add default route&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[ve-101]# /sbin/ifconfig eth0 10.0.0.1 netmask 255.255.255.255&lt;br /&gt;
[ve-101]# /sbin/ip route add 192.168.0.1 dev eth0&lt;br /&gt;
[ve-101]# /sbin/ip route default via 192.168.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In a Debian container, you can configure this permanently by using &amp;lt;tt&amp;gt;/etc/network/interfaces&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
auto eth0&lt;br /&gt;
iface eth0 inet static&lt;br /&gt;
        address 10.0.0.1&lt;br /&gt;
        netmask 255.255.255.255&lt;br /&gt;
        up /sbin/ip route add 192.168.0.1 dev eth0&lt;br /&gt;
        up /sbin/ip route add default via 192.168.0.1&lt;br /&gt;
&amp;lt;/pre&amp;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>StalkR</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_Ethernet_device&amp;diff=7513</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=7513"/>
		<updated>2009-09-07T01:20:35Z</updated>

		<summary type="html">&lt;p&gt;StalkR: /* Configure device in CT */ netmask missing&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;
Assuming you have 192.168.0.0/24 on your LAN, you will learn how to integrate a container in this LAN using veth.&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 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;
=== Using a directly routed IPv4 with virtual Ethernet device ===&lt;br /&gt;
&lt;br /&gt;
==== Situation ====&lt;br /&gt;
Hardware Node (HN/CT0) has 192.168.0.1/24 with router 192.168.0.254.&lt;br /&gt;
&lt;br /&gt;
We also know that IPv4 10.0.0.1/32 is directly routed to 192.168.0.1 (this is called a ''fail-over IP'').&lt;br /&gt;
&lt;br /&gt;
We want to give this directly routed IPv4 address to a container (CT).&lt;br /&gt;
&lt;br /&gt;
==== Start container ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl start 101&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 device and add route in CT0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ifconfig veth101.0 0&lt;br /&gt;
[host-node]# ip route add 10.0.0.1 dev veth101.0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure that you have IPv4 forwarding enabled.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/ip_forward&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/veth101.0/forwarding&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can permanently set this by using &amp;lt;tt&amp;gt;/etc/sysctl.conf&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Configure device in CT ====&lt;br /&gt;
&lt;br /&gt;
1. Configure IP address&lt;br /&gt;
&lt;br /&gt;
2. Add gateway&lt;br /&gt;
&lt;br /&gt;
3. Add default route&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[ve-101]# /sbin/ifconfig eth0 10.0.0.1 netmask 255.255.255.255&lt;br /&gt;
[ve-101]# /sbin/ip route add 192.168.0.1 dev eth0&lt;br /&gt;
[ve-101]# /sbin/ip route default via 192.168.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In a Debian container, you can configure this permanently by using &amp;lt;tt&amp;gt;/etc/network/interfaces&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
auto eth0&lt;br /&gt;
iface eth0 inet static&lt;br /&gt;
        address 10.0.0.1&lt;br /&gt;
        netmask 255.255.255.255&lt;br /&gt;
        up /sbin/ip route add 192.168.0.1 dev eth0&lt;br /&gt;
        up /sbin/ip route add default via 192.168.0.1&lt;br /&gt;
&amp;lt;/pre&amp;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>StalkR</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_Ethernet_device&amp;diff=7512</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=7512"/>
		<updated>2009-09-07T01:19:05Z</updated>

		<summary type="html">&lt;p&gt;StalkR: /* Common configurations with virtual Ethernet devices */  new section : Using a directly routed IPv4 with virtual Ethernet device&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;
Assuming you have 192.168.0.0/24 on your LAN, you will learn how to integrate a container in this LAN using veth.&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 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;
=== Using a directly routed IPv4 with virtual Ethernet device ===&lt;br /&gt;
&lt;br /&gt;
==== Situation ====&lt;br /&gt;
Hardware Node (HN/CT0) has 192.168.0.1/24 with router 192.168.0.254.&lt;br /&gt;
&lt;br /&gt;
We also know that IPv4 10.0.0.1/32 is directly routed to 192.168.0.1 (this is called a ''fail-over IP'').&lt;br /&gt;
&lt;br /&gt;
We want to give this directly routed IPv4 address to a container (CT).&lt;br /&gt;
&lt;br /&gt;
==== Start container ====&lt;br /&gt;
&lt;br /&gt;
 [host-node]# vzctl start 101&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 device and add route in CT0 ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# ifconfig veth101.0 0&lt;br /&gt;
[host-node]# ip route add 10.0.0.1 dev veth101.0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Make sure that you have IPv4 forwarding enabled.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[host-node]# echo 1 &amp;gt; /proc/sys/net/ipv4/ip_forward&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/veth101.0/forwarding&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can permanently set this by using &amp;lt;tt&amp;gt;/etc/sysctl.conf&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Configure device in CT ====&lt;br /&gt;
&lt;br /&gt;
1. Configure IP address&lt;br /&gt;
&lt;br /&gt;
2. Add gateway&lt;br /&gt;
&lt;br /&gt;
3. Add default route&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[ve-101]# /sbin/ifconfig eth0 10.0.0.1&lt;br /&gt;
[ve-101]# /sbin/ip route add 192.168.0.1 dev eth0&lt;br /&gt;
[ve-101]# /sbin/ip route default via 192.168.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In a Debian container, you can configure this permanently by using &amp;lt;tt&amp;gt;/etc/network/interfaces&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
auto eth0&lt;br /&gt;
iface eth0 inet static&lt;br /&gt;
        address 10.0.0.1&lt;br /&gt;
        netmask 255.255.255.255&lt;br /&gt;
        up /sbin/ip route add 192.168.0.1 dev eth0&lt;br /&gt;
        up /sbin/ip route add default via 192.168.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&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>StalkR</name></author>
		
	</entry>
</feed>