<?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=SergeyIvanov</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=SergeyIvanov"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/SergeyIvanov"/>
	<updated>2026-05-02T17:21:26Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=11786</id>
		<title>Using private IPs for Hardware Nodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=11786"/>
		<updated>2012-01-04T15:18:54Z</updated>

		<summary type="html">&lt;p&gt;SergeyIvanov: fix link. - Sergey Ivanov&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes how to assign public IPs to containers running on OVZ Hardware Nodes in case you have a following network topology:&lt;br /&gt;
&lt;br /&gt;
[[Image:PrivateIPs_fig1.gif|An initial network topology]]&lt;br /&gt;
&lt;br /&gt;
== Using a spare IP in the same range ==&lt;br /&gt;
If you have a spare IP to use, you could assign this as a subinterface and use this as nameserver:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[HN] ifconfig eth0:1 *.*.*.*&lt;br /&gt;
[HN] vzctl set 101 --nameserver *.*.*.*&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
This configuration was tested on a RHEL5 OpenVZ Hardware Node and a container based on a Fedora Core 5 template.&lt;br /&gt;
Other host OSs and templates might require some configuration changes, please add corresponding OS specific changes if you've faced any.&lt;br /&gt;
&lt;br /&gt;
This article assumes the presence of 'brctl', 'ip' and 'ifconfig' utils. You may need to install missing packages like 'bridge-utils'/'iproute'/'net-tools' or others which contain those utilities.&lt;br /&gt;
&lt;br /&gt;
This article assumes you have already [[Quick installation|installed OpenVZ]],&lt;br /&gt;
prepared the [[OS template cache]](s) and have&lt;br /&gt;
[[Basic_operations_in_OpenVZ_environment|container(s) created]]. If not, follow the links to perform the steps needed.&lt;br /&gt;
{{Note|don't assign an IP after container creation.}}&lt;br /&gt;
&lt;br /&gt;
== An OVZ Hardware Node has the only one Ethernet interface ==&lt;br /&gt;
(assume eth0)&lt;br /&gt;
&lt;br /&gt;
=== Hardware Node configuration ===&lt;br /&gt;
&lt;br /&gt;
==== Create a bridge device ====&lt;br /&gt;
 [HN]# brctl addbr br0&lt;br /&gt;
&lt;br /&gt;
==== Remove an IP from eth0 interface ====&lt;br /&gt;
 [HN]# ifconfig eth0 0&lt;br /&gt;
&lt;br /&gt;
==== Add eth0 interface into the bridge ====&lt;br /&gt;
 [HN]# brctl addif br0 eth0&lt;br /&gt;
 &lt;br /&gt;
==== Assign the IP to the bridge ====&lt;br /&gt;
(the same that was assigned on eth0 earlier)&lt;br /&gt;
 [HN]# ifconfig br0 10.0.0.2/24&lt;br /&gt;
&lt;br /&gt;
==== Resurrect the default routing ====&lt;br /&gt;
 [HN]# ip route add default via 10.0.0.1 dev br0&lt;br /&gt;
 &lt;br /&gt;
{{Warning|if you are '''configuring''' the node '''remotely''' you '''must''' prepare a '''script''' with the above commands and run it in background with the redirected output or you'll '''lose the access''' to the Node.}}&lt;br /&gt;
&lt;br /&gt;
==== A script example ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[HN]# cat /tmp/br_add &lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
brctl addbr br0&lt;br /&gt;
ifconfig eth0 0 &lt;br /&gt;
brctl addif br0 eth0 &lt;br /&gt;
ifconfig br0 10.0.0.2/24 &lt;br /&gt;
ip route add default via 10.0.0.1 dev br0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [HN]# /tmp/br_add &amp;gt;/dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
=== Container configuration ===&lt;br /&gt;
&lt;br /&gt;
==== Start a container ====&lt;br /&gt;
 [HN]# vzctl start 101&lt;br /&gt;
&lt;br /&gt;
==== Add a [[Virtual_Ethernet_device|veth interface]] to the container ====&lt;br /&gt;
 [HN]# vzctl set 101 --netif_add eth0 --save&lt;br /&gt;
&lt;br /&gt;
==== Set up an IP to the newly created container's veth interface ====&lt;br /&gt;
 [HN]# vzctl exec 101 ifconfig eth0 85.86.87.195/26&lt;br /&gt;
 &lt;br /&gt;
==== Add the container's veth interface to the bridge ====&lt;br /&gt;
 [HN]# brctl addif br0 veth101.0&lt;br /&gt;
&lt;br /&gt;
{{Note|There will be a delay of about 15 seconds(default for 2.6.18 kernel) while the bridge software runs STP to detect loops and transitions the veth interface to the forwarding state.&lt;br /&gt;
&amp;lt;!-- /sys/class/net/$BR_NAME/bridge/forward_delay in SEC*USER_HZ --&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==== Set up the default route for the container ====&lt;br /&gt;
 [HN]# vzctl exec 101 ip route add default via 85.86.87.193 dev eth0&lt;br /&gt;
 &lt;br /&gt;
==== (Optional) Add CT↔HN routes ====&lt;br /&gt;
The above configuration provides the following connections:&lt;br /&gt;
* CT X ↔ CT Y (where CT X and CT Y can locate on any OVZ HN)&lt;br /&gt;
* CT   ↔ Internet&lt;br /&gt;
&lt;br /&gt;
Note that&lt;br /&gt;
&lt;br /&gt;
* The accessability of the CT from the HN depends on the local gateway providing NAT (probably - yes)&lt;br /&gt;
&lt;br /&gt;
* The accessability of the HN from the CT depends on the ISP gateway being aware of the local network (probably not)&lt;br /&gt;
&lt;br /&gt;
So to provide CT ↔ HN accessibility despite the gateways' configuration you can add the following routes:&lt;br /&gt;
&lt;br /&gt;
 [HN]# ip route add 85.86.87.195 dev br0&lt;br /&gt;
 [HN]# vzctl exec 101 ip route add 10.0.0.2 dev eth0&lt;br /&gt;
&lt;br /&gt;
=== Resulting OpenVZ Node configuration ===&lt;br /&gt;
[[Image:PrivateIPs_fig2.gif|Resulting OpenVZ Node configuration]]&lt;br /&gt;
&lt;br /&gt;
=== Making the configuration persistent ===&lt;br /&gt;
&lt;br /&gt;
==== Set up a bridge on a HN ====&lt;br /&gt;
This can be done by configuring the &amp;lt;code&amp;gt;ifcfg-*&amp;lt;/code&amp;gt; files located in &amp;lt;code&amp;gt;/etc/sysconfig/network-scripts/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assuming you had a configuration file (e.g. &amp;lt;code&amp;gt;ifcfg-eth0&amp;lt;/code&amp;gt;) like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
IPADDR=10.0.0.2&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=10.0.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To automatically create bridge &amp;lt;code&amp;gt;br0&amp;lt;/code&amp;gt;  you can create &amp;lt;code&amp;gt;ifcfg-br0&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=br0&lt;br /&gt;
TYPE=Bridge&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
IPADDR=10.0.0.2&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=10.0.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and edit &amp;lt;code&amp;gt;ifcfg-eth0&amp;lt;/code&amp;gt; to add the &amp;lt;code&amp;gt;eth0&amp;lt;/code&amp;gt; interface into the bridge &amp;lt;code&amp;gt;br0&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
BRIDGE=br0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Edit the container's configuration ====&lt;br /&gt;
Add these parameters to the &amp;lt;code&amp;gt;/etc/vz/conf/$CTID.conf&amp;lt;/code&amp;gt; file which will be used during the network configuration:&lt;br /&gt;
* Add &amp;lt;code&amp;gt;VETH_IP_ADDRESS=&amp;quot;IP/MASK&amp;quot;&amp;lt;/code&amp;gt; (a container can have multiple IPs separated by spaces)&lt;br /&gt;
* Add &amp;lt;code&amp;gt;VE_DEFAULT_GATEWAY=&amp;quot;CT DEFAULT GATEWAY&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
* Add &amp;lt;code&amp;gt;BRIDGEDEV=&amp;quot;BRIDGE NAME&amp;quot;&amp;lt;/code&amp;gt; (a bridge name to which the container veth interface should be added)&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Network customization section&lt;br /&gt;
VETH_IP_ADDRESS=&amp;quot;85.86.87.195/26&amp;quot;&lt;br /&gt;
VE_DEFAULT_GATEWAY=&amp;quot;85.86.87.193&amp;quot;&lt;br /&gt;
BRIDGEDEV=&amp;quot;br0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a custom network configuration script ====&lt;br /&gt;
which should be called each time a container is started (e.g. &amp;lt;code&amp;gt;/usr/sbin/vznetcfg.custom&amp;lt;/code&amp;gt;):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# /usr/sbin/vznetcfg.custom&lt;br /&gt;
# a script to bring up bridged network interfaces (veth's) in a container&lt;br /&gt;
&lt;br /&gt;
GLOBALCONFIGFILE=/etc/vz/vz.conf&lt;br /&gt;
CTCONFIGFILE=/etc/vz/conf/$VEID.conf&lt;br /&gt;
vzctl=/usr/sbin/vzctl&lt;br /&gt;
brctl=/usr/sbin/brctl&lt;br /&gt;
ip=/sbin/ip&lt;br /&gt;
ifconfig=/sbin/ifconfig&lt;br /&gt;
. $GLOBALCONFIGFILE&lt;br /&gt;
. $CTCONFIGFILE&lt;br /&gt;
&lt;br /&gt;
NETIF_OPTIONS=`echo $NETIF | sed 's/,/\n/g'`&lt;br /&gt;
for str in $NETIF_OPTIONS; do \&lt;br /&gt;
        # getting 'ifname' parameter value&lt;br /&gt;
        if  echo &amp;quot;$str&amp;quot; | grep -o &amp;quot;^ifname=&amp;quot; ; then&lt;br /&gt;
                # remove the parameter name from the string (along with '=')&lt;br /&gt;
                CTIFNAME=${str#*=};&lt;br /&gt;
        fi&lt;br /&gt;
        # getting 'host_ifname' parameter value&lt;br /&gt;
        if  echo &amp;quot;$str&amp;quot; | grep -o &amp;quot;^host_ifname=&amp;quot; ; then&lt;br /&gt;
                # remove the parameter name from the string (along with '=')&lt;br /&gt;
                VZHOSTIF=${str#*=};&lt;br /&gt;
        fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VETH_IP_ADDRESS&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;According to $CONFIGFILE CT$VEID has no veth IPs configured.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&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;$CTIFNAME&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Corrupted $CONFIGFILE: no 'ifname' defined for host_ifname $VZHOSTIF.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Initializing interface $VZHOSTIF for CT$VEID.&amp;quot;&lt;br /&gt;
$ifconfig $VZHOSTIF 0&lt;br /&gt;
&lt;br /&gt;
CTROUTEDEV=$VZHOSTIF&lt;br /&gt;
&lt;br /&gt;
if [ -n &amp;quot;$BRIDGEDEV&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Adding interface $VZHOSTIF to the bridge $BRIDGEDEV.&amp;quot;&lt;br /&gt;
   CTROUTEDEV=$BRIDGEDEV&lt;br /&gt;
   $brctl addif $BRIDGEDEV $VZHOSTIF&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Up the interface $CTIFNAME link in CT$VEID&lt;br /&gt;
$vzctl exec $VEID $ip link set $CTIFNAME up&lt;br /&gt;
&lt;br /&gt;
for IP in $VETH_IP_ADDRESS; do&lt;br /&gt;
   echo &amp;quot;Adding an IP $IP to the $CTIFNAME for CT$VEID.&amp;quot;&lt;br /&gt;
   $vzctl exec $VEID $ip address add $IP dev $CTIFNAME&lt;br /&gt;
&lt;br /&gt;
   # removing the netmask&lt;br /&gt;
   IP_STRIP=${IP%%/*};&lt;br /&gt;
&lt;br /&gt;
   echo &amp;quot;Adding a route from CT0 to CT$VEID using $IP_STRIP.&amp;quot;&lt;br /&gt;
   $ip route add $IP_STRIP dev $CTROUTEDEV&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
if [ -n &amp;quot;$CT0_IP&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Adding a route from CT$VEID to CT0.&amp;quot;&lt;br /&gt;
   $vzctl exec $VEID $ip route add $CT0_IP dev $CTIFNAME&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ -n &amp;quot;$VE_DEFAULT_GATEWAY&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Setting $VE_DEFAULT_GATEWAY as a default gateway for CT$VEID.&amp;quot;&lt;br /&gt;
   $vzctl exec $VEID \&lt;br /&gt;
        $ip route add default via $VE_DEFAULT_GATEWAY dev $CTIFNAME&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;small&amp;gt;Note: this script can be easily extended to work for multiple triples &amp;amp;lt;bridge, ip address, veth device&amp;amp;gt;, see http://sysadmin-ivanov.blogspot.com/2008/02/2-veth-with-2-bridges-on-openvz-at.html &amp;lt;/small&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Make the script to be run on a container start ====&lt;br /&gt;
In order to run above script on a container start create the file&lt;br /&gt;
&amp;lt;code&amp;gt;/etc/vz/vznet.conf&amp;lt;/code&amp;gt; with the following contents:&lt;br /&gt;
&lt;br /&gt;
 EXTERNAL_SCRIPT=&amp;quot;/usr/sbin/vznetcfg.custom&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{Note|&amp;lt;code&amp;gt;/usr/sbin/vznetcfg.custom&amp;lt;/code&amp;gt; should be executable (chmod +x /usr/sbin/vznetcfg.custom)}}&lt;br /&gt;
&lt;br /&gt;
{{Note|When CT is stoped there are HW → CT route(s) still present in route table. We can use On-umount script for solve this.}}&lt;br /&gt;
&lt;br /&gt;
==== Create On-umount script for remove HW → CT route(s) ====&lt;br /&gt;
which should be called each time a container with VEID (&amp;lt;code&amp;gt;/etc/vz/conf/$VEID.umount&amp;lt;/code&amp;gt;), or any container (&amp;lt;code&amp;gt;/etc/vz/conf/vps.umount&amp;lt;/code&amp;gt;) is stop.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# /etc/vz/conf/$VEID.umount or /etc/vz/conf/vps.umount&lt;br /&gt;
# a script to remove routes to container with veth-bridge from bridge &lt;br /&gt;
&lt;br /&gt;
CTCONFIGFILE=/etc/vz/conf/$VEID.conf&lt;br /&gt;
ip=/sbin/ip&lt;br /&gt;
. $CTCONFIGFILE&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VETH_IP_ADDRESS&amp;quot; ]; then&lt;br /&gt;
   exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$BRIDGEDEV&amp;quot; ]; then&lt;br /&gt;
   exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
for IP in $VETH_IP_ADDRESS; do&lt;br /&gt;
   # removing the netmask&lt;br /&gt;
   IP_STRIP=${IP%%/*};&lt;br /&gt;
   &lt;br /&gt;
   echo &amp;quot;Remove a route from CT0 to CT$VEID using $IP_STRIP.&amp;quot;&lt;br /&gt;
   $ip route del $IP_STRIP dev $BRIDGEDEV&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|The script should be executable (chmod +x /etc/vz/conf/vps.umount)}}&lt;br /&gt;
&lt;br /&gt;
==== Setting the route CT → HN ====&lt;br /&gt;
To set up a route from the CT to the HN, the custom script has to get a HN IP (the $CT0_IP variable in the script). There are several ways to specify it:&lt;br /&gt;
&lt;br /&gt;
# Add an entry CT0_IP=&amp;quot;CT0 IP&amp;quot; to the &amp;lt;code&amp;gt;$VEID.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
# Add an entry CT0_IP=&amp;quot;CT0 IP&amp;quot; to the &amp;lt;code&amp;gt;/etc/vz/vz.conf&amp;lt;/code&amp;gt; (the global configuration config file)&lt;br /&gt;
# Implement some smart algorithm to determine the CT0 IP right in the custom network configuration script&lt;br /&gt;
&lt;br /&gt;
Each variant has its pros and cons, nevertheless for HN static IP configuration variant 2 seems to be acceptable (and the most simple).&lt;br /&gt;
&lt;br /&gt;
== An OpenVZ Hardware Node has two Ethernet interfaces ==&lt;br /&gt;
Assuming you have 2 interfaces eth0 and eth1 and want to separate local traffic (10.0.0.0/24) from  external traffic.&lt;br /&gt;
Let's assign eth0 for the external traffic and eth1 for the local one.&lt;br /&gt;
&lt;br /&gt;
If there is no need to make the container accessible from the HN and vice versa, it's enough to replace 'br0' with 'eth1' in the following steps of the above configuration:&lt;br /&gt;
* Hardware Node configuration → [[Using_private_IPs_for_Hardware_Nodes#Assign_the_IP_to_the_bridge|Assign the IP to the bridge]]&lt;br /&gt;
* Hardware Node configuration → [[Using_private_IPs_for_Hardware_Nodes#Resurrect_the_default_routing|Resurrect the default routing]]&lt;br /&gt;
&lt;br /&gt;
It is nesessary to set a local IP for 'br0' to ensure CT ↔ HN connection availability.&lt;br /&gt;
&lt;br /&gt;
== Putting containers to different subnetworks ==&lt;br /&gt;
It's enough to set up the correct $VETH_IP_ADDRESS and $VE_DEFAULT_GATEWAY values in the &lt;br /&gt;
[[Using_private_IPs_for_Hardware_Nodes#Edit_the_container.27s_configuration|above 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;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>SergeyIvanov</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=11785</id>
		<title>Using private IPs for Hardware Nodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=11785"/>
		<updated>2012-01-04T15:17:38Z</updated>

		<summary type="html">&lt;p&gt;SergeyIvanov: I have moved it to another blog. - Sergey Ivanov&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes how to assign public IPs to containers running on OVZ Hardware Nodes in case you have a following network topology:&lt;br /&gt;
&lt;br /&gt;
[[Image:PrivateIPs_fig1.gif|An initial network topology]]&lt;br /&gt;
&lt;br /&gt;
== Using a spare IP in the same range ==&lt;br /&gt;
If you have a spare IP to use, you could assign this as a subinterface and use this as nameserver:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;[HN] ifconfig eth0:1 *.*.*.*&lt;br /&gt;
[HN] vzctl set 101 --nameserver *.*.*.*&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
This configuration was tested on a RHEL5 OpenVZ Hardware Node and a container based on a Fedora Core 5 template.&lt;br /&gt;
Other host OSs and templates might require some configuration changes, please add corresponding OS specific changes if you've faced any.&lt;br /&gt;
&lt;br /&gt;
This article assumes the presence of 'brctl', 'ip' and 'ifconfig' utils. You may need to install missing packages like 'bridge-utils'/'iproute'/'net-tools' or others which contain those utilities.&lt;br /&gt;
&lt;br /&gt;
This article assumes you have already [[Quick installation|installed OpenVZ]],&lt;br /&gt;
prepared the [[OS template cache]](s) and have&lt;br /&gt;
[[Basic_operations_in_OpenVZ_environment|container(s) created]]. If not, follow the links to perform the steps needed.&lt;br /&gt;
{{Note|don't assign an IP after container creation.}}&lt;br /&gt;
&lt;br /&gt;
== An OVZ Hardware Node has the only one Ethernet interface ==&lt;br /&gt;
(assume eth0)&lt;br /&gt;
&lt;br /&gt;
=== Hardware Node configuration ===&lt;br /&gt;
&lt;br /&gt;
==== Create a bridge device ====&lt;br /&gt;
 [HN]# brctl addbr br0&lt;br /&gt;
&lt;br /&gt;
==== Remove an IP from eth0 interface ====&lt;br /&gt;
 [HN]# ifconfig eth0 0&lt;br /&gt;
&lt;br /&gt;
==== Add eth0 interface into the bridge ====&lt;br /&gt;
 [HN]# brctl addif br0 eth0&lt;br /&gt;
 &lt;br /&gt;
==== Assign the IP to the bridge ====&lt;br /&gt;
(the same that was assigned on eth0 earlier)&lt;br /&gt;
 [HN]# ifconfig br0 10.0.0.2/24&lt;br /&gt;
&lt;br /&gt;
==== Resurrect the default routing ====&lt;br /&gt;
 [HN]# ip route add default via 10.0.0.1 dev br0&lt;br /&gt;
 &lt;br /&gt;
{{Warning|if you are '''configuring''' the node '''remotely''' you '''must''' prepare a '''script''' with the above commands and run it in background with the redirected output or you'll '''lose the access''' to the Node.}}&lt;br /&gt;
&lt;br /&gt;
==== A script example ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[HN]# cat /tmp/br_add &lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
brctl addbr br0&lt;br /&gt;
ifconfig eth0 0 &lt;br /&gt;
brctl addif br0 eth0 &lt;br /&gt;
ifconfig br0 10.0.0.2/24 &lt;br /&gt;
ip route add default via 10.0.0.1 dev br0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [HN]# /tmp/br_add &amp;gt;/dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
=== Container configuration ===&lt;br /&gt;
&lt;br /&gt;
==== Start a container ====&lt;br /&gt;
 [HN]# vzctl start 101&lt;br /&gt;
&lt;br /&gt;
==== Add a [[Virtual_Ethernet_device|veth interface]] to the container ====&lt;br /&gt;
 [HN]# vzctl set 101 --netif_add eth0 --save&lt;br /&gt;
&lt;br /&gt;
==== Set up an IP to the newly created container's veth interface ====&lt;br /&gt;
 [HN]# vzctl exec 101 ifconfig eth0 85.86.87.195/26&lt;br /&gt;
 &lt;br /&gt;
==== Add the container's veth interface to the bridge ====&lt;br /&gt;
 [HN]# brctl addif br0 veth101.0&lt;br /&gt;
&lt;br /&gt;
{{Note|There will be a delay of about 15 seconds(default for 2.6.18 kernel) while the bridge software runs STP to detect loops and transitions the veth interface to the forwarding state.&lt;br /&gt;
&amp;lt;!-- /sys/class/net/$BR_NAME/bridge/forward_delay in SEC*USER_HZ --&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==== Set up the default route for the container ====&lt;br /&gt;
 [HN]# vzctl exec 101 ip route add default via 85.86.87.193 dev eth0&lt;br /&gt;
 &lt;br /&gt;
==== (Optional) Add CT↔HN routes ====&lt;br /&gt;
The above configuration provides the following connections:&lt;br /&gt;
* CT X ↔ CT Y (where CT X and CT Y can locate on any OVZ HN)&lt;br /&gt;
* CT   ↔ Internet&lt;br /&gt;
&lt;br /&gt;
Note that&lt;br /&gt;
&lt;br /&gt;
* The accessability of the CT from the HN depends on the local gateway providing NAT (probably - yes)&lt;br /&gt;
&lt;br /&gt;
* The accessability of the HN from the CT depends on the ISP gateway being aware of the local network (probably not)&lt;br /&gt;
&lt;br /&gt;
So to provide CT ↔ HN accessibility despite the gateways' configuration you can add the following routes:&lt;br /&gt;
&lt;br /&gt;
 [HN]# ip route add 85.86.87.195 dev br0&lt;br /&gt;
 [HN]# vzctl exec 101 ip route add 10.0.0.2 dev eth0&lt;br /&gt;
&lt;br /&gt;
=== Resulting OpenVZ Node configuration ===&lt;br /&gt;
[[Image:PrivateIPs_fig2.gif|Resulting OpenVZ Node configuration]]&lt;br /&gt;
&lt;br /&gt;
=== Making the configuration persistent ===&lt;br /&gt;
&lt;br /&gt;
==== Set up a bridge on a HN ====&lt;br /&gt;
This can be done by configuring the &amp;lt;code&amp;gt;ifcfg-*&amp;lt;/code&amp;gt; files located in &amp;lt;code&amp;gt;/etc/sysconfig/network-scripts/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assuming you had a configuration file (e.g. &amp;lt;code&amp;gt;ifcfg-eth0&amp;lt;/code&amp;gt;) like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
IPADDR=10.0.0.2&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=10.0.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To automatically create bridge &amp;lt;code&amp;gt;br0&amp;lt;/code&amp;gt;  you can create &amp;lt;code&amp;gt;ifcfg-br0&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=br0&lt;br /&gt;
TYPE=Bridge&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
IPADDR=10.0.0.2&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=10.0.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and edit &amp;lt;code&amp;gt;ifcfg-eth0&amp;lt;/code&amp;gt; to add the &amp;lt;code&amp;gt;eth0&amp;lt;/code&amp;gt; interface into the bridge &amp;lt;code&amp;gt;br0&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
BRIDGE=br0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Edit the container's configuration ====&lt;br /&gt;
Add these parameters to the &amp;lt;code&amp;gt;/etc/vz/conf/$CTID.conf&amp;lt;/code&amp;gt; file which will be used during the network configuration:&lt;br /&gt;
* Add &amp;lt;code&amp;gt;VETH_IP_ADDRESS=&amp;quot;IP/MASK&amp;quot;&amp;lt;/code&amp;gt; (a container can have multiple IPs separated by spaces)&lt;br /&gt;
* Add &amp;lt;code&amp;gt;VE_DEFAULT_GATEWAY=&amp;quot;CT DEFAULT GATEWAY&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
* Add &amp;lt;code&amp;gt;BRIDGEDEV=&amp;quot;BRIDGE NAME&amp;quot;&amp;lt;/code&amp;gt; (a bridge name to which the container veth interface should be added)&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Network customization section&lt;br /&gt;
VETH_IP_ADDRESS=&amp;quot;85.86.87.195/26&amp;quot;&lt;br /&gt;
VE_DEFAULT_GATEWAY=&amp;quot;85.86.87.193&amp;quot;&lt;br /&gt;
BRIDGEDEV=&amp;quot;br0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a custom network configuration script ====&lt;br /&gt;
which should be called each time a container is started (e.g. &amp;lt;code&amp;gt;/usr/sbin/vznetcfg.custom&amp;lt;/code&amp;gt;):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# /usr/sbin/vznetcfg.custom&lt;br /&gt;
# a script to bring up bridged network interfaces (veth's) in a container&lt;br /&gt;
&lt;br /&gt;
GLOBALCONFIGFILE=/etc/vz/vz.conf&lt;br /&gt;
CTCONFIGFILE=/etc/vz/conf/$VEID.conf&lt;br /&gt;
vzctl=/usr/sbin/vzctl&lt;br /&gt;
brctl=/usr/sbin/brctl&lt;br /&gt;
ip=/sbin/ip&lt;br /&gt;
ifconfig=/sbin/ifconfig&lt;br /&gt;
. $GLOBALCONFIGFILE&lt;br /&gt;
. $CTCONFIGFILE&lt;br /&gt;
&lt;br /&gt;
NETIF_OPTIONS=`echo $NETIF | sed 's/,/\n/g'`&lt;br /&gt;
for str in $NETIF_OPTIONS; do \&lt;br /&gt;
        # getting 'ifname' parameter value&lt;br /&gt;
        if  echo &amp;quot;$str&amp;quot; | grep -o &amp;quot;^ifname=&amp;quot; ; then&lt;br /&gt;
                # remove the parameter name from the string (along with '=')&lt;br /&gt;
                CTIFNAME=${str#*=};&lt;br /&gt;
        fi&lt;br /&gt;
        # getting 'host_ifname' parameter value&lt;br /&gt;
        if  echo &amp;quot;$str&amp;quot; | grep -o &amp;quot;^host_ifname=&amp;quot; ; then&lt;br /&gt;
                # remove the parameter name from the string (along with '=')&lt;br /&gt;
                VZHOSTIF=${str#*=};&lt;br /&gt;
        fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VETH_IP_ADDRESS&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;According to $CONFIGFILE CT$VEID has no veth IPs configured.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&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;$CTIFNAME&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Corrupted $CONFIGFILE: no 'ifname' defined for host_ifname $VZHOSTIF.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Initializing interface $VZHOSTIF for CT$VEID.&amp;quot;&lt;br /&gt;
$ifconfig $VZHOSTIF 0&lt;br /&gt;
&lt;br /&gt;
CTROUTEDEV=$VZHOSTIF&lt;br /&gt;
&lt;br /&gt;
if [ -n &amp;quot;$BRIDGEDEV&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Adding interface $VZHOSTIF to the bridge $BRIDGEDEV.&amp;quot;&lt;br /&gt;
   CTROUTEDEV=$BRIDGEDEV&lt;br /&gt;
   $brctl addif $BRIDGEDEV $VZHOSTIF&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Up the interface $CTIFNAME link in CT$VEID&lt;br /&gt;
$vzctl exec $VEID $ip link set $CTIFNAME up&lt;br /&gt;
&lt;br /&gt;
for IP in $VETH_IP_ADDRESS; do&lt;br /&gt;
   echo &amp;quot;Adding an IP $IP to the $CTIFNAME for CT$VEID.&amp;quot;&lt;br /&gt;
   $vzctl exec $VEID $ip address add $IP dev $CTIFNAME&lt;br /&gt;
&lt;br /&gt;
   # removing the netmask&lt;br /&gt;
   IP_STRIP=${IP%%/*};&lt;br /&gt;
&lt;br /&gt;
   echo &amp;quot;Adding a route from CT0 to CT$VEID using $IP_STRIP.&amp;quot;&lt;br /&gt;
   $ip route add $IP_STRIP dev $CTROUTEDEV&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
if [ -n &amp;quot;$CT0_IP&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Adding a route from CT$VEID to CT0.&amp;quot;&lt;br /&gt;
   $vzctl exec $VEID $ip route add $CT0_IP dev $CTIFNAME&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ -n &amp;quot;$VE_DEFAULT_GATEWAY&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Setting $VE_DEFAULT_GATEWAY as a default gateway for CT$VEID.&amp;quot;&lt;br /&gt;
   $vzctl exec $VEID \&lt;br /&gt;
        $ip route add default via $VE_DEFAULT_GATEWAY dev $CTIFNAME&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;small&amp;gt;Note: this script can be easily extended to work for multiple triples &amp;amp;lt;bridge, ip address, veth device&amp;amp;gt;, see http://sysadmin-ivanov.blogspot.com/2009/11/autofonix.html &amp;lt;/small&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Make the script to be run on a container start ====&lt;br /&gt;
In order to run above script on a container start create the file&lt;br /&gt;
&amp;lt;code&amp;gt;/etc/vz/vznet.conf&amp;lt;/code&amp;gt; with the following contents:&lt;br /&gt;
&lt;br /&gt;
 EXTERNAL_SCRIPT=&amp;quot;/usr/sbin/vznetcfg.custom&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{Note|&amp;lt;code&amp;gt;/usr/sbin/vznetcfg.custom&amp;lt;/code&amp;gt; should be executable (chmod +x /usr/sbin/vznetcfg.custom)}}&lt;br /&gt;
&lt;br /&gt;
{{Note|When CT is stoped there are HW → CT route(s) still present in route table. We can use On-umount script for solve this.}}&lt;br /&gt;
&lt;br /&gt;
==== Create On-umount script for remove HW → CT route(s) ====&lt;br /&gt;
which should be called each time a container with VEID (&amp;lt;code&amp;gt;/etc/vz/conf/$VEID.umount&amp;lt;/code&amp;gt;), or any container (&amp;lt;code&amp;gt;/etc/vz/conf/vps.umount&amp;lt;/code&amp;gt;) is stop.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# /etc/vz/conf/$VEID.umount or /etc/vz/conf/vps.umount&lt;br /&gt;
# a script to remove routes to container with veth-bridge from bridge &lt;br /&gt;
&lt;br /&gt;
CTCONFIGFILE=/etc/vz/conf/$VEID.conf&lt;br /&gt;
ip=/sbin/ip&lt;br /&gt;
. $CTCONFIGFILE&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VETH_IP_ADDRESS&amp;quot; ]; then&lt;br /&gt;
   exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$BRIDGEDEV&amp;quot; ]; then&lt;br /&gt;
   exit 0&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
for IP in $VETH_IP_ADDRESS; do&lt;br /&gt;
   # removing the netmask&lt;br /&gt;
   IP_STRIP=${IP%%/*};&lt;br /&gt;
   &lt;br /&gt;
   echo &amp;quot;Remove a route from CT0 to CT$VEID using $IP_STRIP.&amp;quot;&lt;br /&gt;
   $ip route del $IP_STRIP dev $BRIDGEDEV&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Note|The script should be executable (chmod +x /etc/vz/conf/vps.umount)}}&lt;br /&gt;
&lt;br /&gt;
==== Setting the route CT → HN ====&lt;br /&gt;
To set up a route from the CT to the HN, the custom script has to get a HN IP (the $CT0_IP variable in the script). There are several ways to specify it:&lt;br /&gt;
&lt;br /&gt;
# Add an entry CT0_IP=&amp;quot;CT0 IP&amp;quot; to the &amp;lt;code&amp;gt;$VEID.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
# Add an entry CT0_IP=&amp;quot;CT0 IP&amp;quot; to the &amp;lt;code&amp;gt;/etc/vz/vz.conf&amp;lt;/code&amp;gt; (the global configuration config file)&lt;br /&gt;
# Implement some smart algorithm to determine the CT0 IP right in the custom network configuration script&lt;br /&gt;
&lt;br /&gt;
Each variant has its pros and cons, nevertheless for HN static IP configuration variant 2 seems to be acceptable (and the most simple).&lt;br /&gt;
&lt;br /&gt;
== An OpenVZ Hardware Node has two Ethernet interfaces ==&lt;br /&gt;
Assuming you have 2 interfaces eth0 and eth1 and want to separate local traffic (10.0.0.0/24) from  external traffic.&lt;br /&gt;
Let's assign eth0 for the external traffic and eth1 for the local one.&lt;br /&gt;
&lt;br /&gt;
If there is no need to make the container accessible from the HN and vice versa, it's enough to replace 'br0' with 'eth1' in the following steps of the above configuration:&lt;br /&gt;
* Hardware Node configuration → [[Using_private_IPs_for_Hardware_Nodes#Assign_the_IP_to_the_bridge|Assign the IP to the bridge]]&lt;br /&gt;
* Hardware Node configuration → [[Using_private_IPs_for_Hardware_Nodes#Resurrect_the_default_routing|Resurrect the default routing]]&lt;br /&gt;
&lt;br /&gt;
It is nesessary to set a local IP for 'br0' to ensure CT ↔ HN connection availability.&lt;br /&gt;
&lt;br /&gt;
== Putting containers to different subnetworks ==&lt;br /&gt;
It's enough to set up the correct $VETH_IP_ADDRESS and $VE_DEFAULT_GATEWAY values in the &lt;br /&gt;
[[Using_private_IPs_for_Hardware_Nodes#Edit_the_container.27s_configuration|above 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;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>SergeyIvanov</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Talk:Virtual_Ethernet_device&amp;diff=11703</id>
		<title>Talk:Virtual Ethernet device</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Talk:Virtual_Ethernet_device&amp;diff=11703"/>
		<updated>2011-12-07T22:14:43Z</updated>

		<summary type="html">&lt;p&gt;SergeyIvanov: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Under Common Configurations -&amp;gt; Simple configuration -&amp;gt; Configure devices in VE0, the example shows&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&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;
being run on the host node, VE0.  I don't think this can be correct, because eth0 exists in VE 101, not VE0. {{unsigned|Andrex|01:11, 15 July 2006}}&lt;br /&gt;
&lt;br /&gt;
: This is correct, because we need to enable forwarding on both network interfaces in VE0 (host-node eth0 and veth101.0) to allow the network packets on one network interface (host-node eth0) to be forwarded to another network interface (veth101.0). The same thing with proxy ARP, we need to enable it on host-node eth0 and veth101.0 network interfaces. --[[User:Major|Major]] 08:42, 17 July 2006 (EDT)&lt;br /&gt;
&lt;br /&gt;
==Multiple persistent Veth interfaces==&lt;br /&gt;
The script for making a persistent bridge get added to a particular host-bridge on startup VPS/VE, doesn't seem to account for having multiple bridges. I have a bridge to a private lan for administrative functions and a bridge to the public network for inbound connections for services. How might one ensure that the vethVEID.x's are hooked up to the bridges on the host every time the VE is started? --[[User:Btrotter|Btrotter]] 05:34, 17 March 2008 (EDT)&lt;br /&gt;
&lt;br /&gt;
: Please take a look at [[Using private IPs for Hardware Nodes]] and http://sysadmin-ivanov.blogspot.com/2008/02/2-veth-with-2-bridges-on-openvz-at.html. There you will find scripts which will help you to manage 2 bridges, and you can simply extend this script to use more then 2 bridges. --[[User:Major|Major]] 15:59, 27 March 2008 (MSK)&lt;br /&gt;
&lt;br /&gt;
==Making a bridged veth-device persistent==&lt;br /&gt;
&lt;br /&gt;
Is this also obsolete, like the section I just deleted? [[User:Mrjcleaver|Mrjcleaver]] 13:35, 31 May 2008 (EDT)&lt;br /&gt;
&lt;br /&gt;
Please leave this in for now! I just needed it today for setup on a Debian HN.&amp;lt;br&amp;gt;&lt;br /&gt;
Also I noted that a crucial word/reference at the end of the following sentence is missing: &amp;quot;4. Of course, the CT's operating system will need to have .&amp;quot; Could someone with wiki-knowledge please restore this (if it was ever known)?&lt;br /&gt;
[[User:Laboa|Laboa]] 22:50, 12. Oct 2008 (CEST)&lt;br /&gt;
&lt;br /&gt;
==Configure devices in CT0==&lt;br /&gt;
These devices under /proc didn't exist for me, but I left them in case they are still needed, even with the new vzctl. [[User:Mrjcleaver|Mrjcleaver]] 13:59, 31 May 2008 (EDT)&lt;br /&gt;
: These files did not exist because you executed a copy/paste, which is incorrect. You should replace 'veth101.0' with veth###.# where ###.# is your relevant VEID (for scripts this should do: 'veth${VEID}.0') according to your VE IDs, and for each VE ID you use veth. -- {{unsigned|79.107.116.50|21:29, 25 November 2009}}&lt;br /&gt;
&lt;br /&gt;
== Creating veth without OpenVZ ==&lt;br /&gt;
&lt;br /&gt;
How to create veth devices pair without of OpenVZ?&lt;br /&gt;
I want something like&lt;br /&gt;
&amp;lt;pre&amp;gt;modprobe veth&lt;br /&gt;
ifconfig veth0 192.168.0.1&lt;br /&gt;
ifconfig veth1 192.168.0.2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Answer: Enable CONFIG_VETH in your kernel, load the veth module and create a new pair with the 'ip' command from the [http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2 iproute2 package].&lt;br /&gt;
&amp;lt;pre&amp;gt;modprobe veth&lt;br /&gt;
ip link add name veth0 type veth peer name veth1&lt;br /&gt;
ifconfig veth0 192.168.0.1&lt;br /&gt;
ifconfig veth1 192.168.0.2&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You may also want to check out this [ftp://robur.slu.se/pub/Linux/bifrost/seminars/workshop-2010-01-27/jens/Namespaces.pdf presentation on namespaces in Linux].&lt;br /&gt;
&lt;br /&gt;
== Using iproute toolset or net-tools toolset ==&lt;br /&gt;
&lt;br /&gt;
Hello,&lt;br /&gt;
&lt;br /&gt;
I propose to substitute all usage of&lt;br /&gt;
&lt;br /&gt;
   ifconfig &amp;lt;device&amp;gt; 0&lt;br /&gt;
&lt;br /&gt;
with &lt;br /&gt;
&lt;br /&gt;
   ip link set &amp;lt;device&amp;gt; up&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Since iproute seems to be a requirement, I think its a good idea to drop support for ifconfig.&lt;/div&gt;</summary>
		<author><name>SergeyIvanov</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_Ethernet_device&amp;diff=11702</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=11702"/>
		<updated>2011-12-07T22:12:15Z</updated>

		<summary type="html">&lt;p&gt;SergeyIvanov: &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;
=== 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;
 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;
=== Removing veth from a CT ===&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;
== 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;
==== 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 add 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;
See the [[VEs and HNs in same subnets]] article.&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;
&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;
vzctl include a 'vznetaddbr' script, which makes use of the ''bridge'' 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;
=== 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;
* Patch: [[Disable venet interface]]&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://sysadmin-ivanov.blogspot.com/2008/02/2-veth-with-2-bridges-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>SergeyIvanov</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=4136</id>
		<title>Using private IPs for Hardware Nodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=4136"/>
		<updated>2008-02-20T06:23:22Z</updated>

		<summary type="html">&lt;p&gt;SergeyIvanov: /* Create a custom network configuration script */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes how to assign public IPs to VEs running on OVZ Hardware Nodes in case you have a following network topology:&lt;br /&gt;
&lt;br /&gt;
[[Image:PrivateIPs_fig1.gif|An initial network topology]]&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
This configuration was tested on a RHEL5 OpenVZ Hardware Node and a VE based on a Fedora Core 5 template.&lt;br /&gt;
Other host OSs and templates might require some configuration changes, please add corresponding OS specific changes if you've faced any.&lt;br /&gt;
&lt;br /&gt;
This article assumes the presence of 'brctl', 'ip' and 'ifconfig' utils. You may need to install missing packages like 'bridge-utils'/'iproute'/'net-tools' or others which contain those utilities.&lt;br /&gt;
&lt;br /&gt;
This article assumes you have already [[Quick installation|installed OpenVZ]], prepared the [[OS template cache]](s) and have [[Basic_operations_in_OpenVZ_environment|VE(s) created]]. If not, follow the links to perform the steps needed.&lt;br /&gt;
{{Note|don't assign an IP after VE creation.}}&lt;br /&gt;
&lt;br /&gt;
== An OVZ Hardware Node has the only one Ethernet interface ==&lt;br /&gt;
(assume eth0)&lt;br /&gt;
&lt;br /&gt;
=== Hardware Node configuration ===&lt;br /&gt;
&lt;br /&gt;
==== Create a bridge device ====&lt;br /&gt;
 [HN]# brctl addbr br0&lt;br /&gt;
&lt;br /&gt;
==== Remove an IP from eth0 interface ====&lt;br /&gt;
 [HN]# ifconfig eth0 0&lt;br /&gt;
&lt;br /&gt;
==== Add eth0 interface into the bridge ====&lt;br /&gt;
 [HN]# brctl addif br0 eth0&lt;br /&gt;
 &lt;br /&gt;
==== Assign the IP to the bridge ====&lt;br /&gt;
(the same that was assigned on eth0 earlier)&lt;br /&gt;
 [HN]# ifconfig br0 10.0.0.2/24&lt;br /&gt;
&lt;br /&gt;
==== Resurrect the default routing ====&lt;br /&gt;
 [HN]# ip route add default via 10.0.0.1 dev br0&lt;br /&gt;
 &lt;br /&gt;
{{Warning|if you are '''configuring''' the node '''remotely''' you '''must''' prepare a '''script''' with the above commands and run it in background with the redirected output or you'll '''lose the access''' to the Node.}}&lt;br /&gt;
&lt;br /&gt;
==== A script example ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[HN]# cat /tmp/br_add &lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
brctl addbr br0&lt;br /&gt;
ifconfig eth0 0 &lt;br /&gt;
brctl addif br0 eth0 &lt;br /&gt;
ifconfig br0 10.0.0.2/24 &lt;br /&gt;
ip route add default via 10.0.0.1 dev br0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [HN]# /tmp/br_add &amp;gt;/dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
=== VE configuration ===&lt;br /&gt;
&lt;br /&gt;
==== Start a VE ====&lt;br /&gt;
 [HN]# vzctl start 101&lt;br /&gt;
&lt;br /&gt;
==== Add a [[Virtual_Ethernet_device|veth interface]] to the VE ====&lt;br /&gt;
 [HN]# vzctl set 101 --netif_add eth0 --save&lt;br /&gt;
&lt;br /&gt;
==== Set up an IP to the newly created VE's veth interface ====&lt;br /&gt;
 [HN]# vzctl exec 101 ifconfig eth0 85.86.87.195/26&lt;br /&gt;
 &lt;br /&gt;
==== Add the VE's veth interface to the bridge ====&lt;br /&gt;
 [HN]# brctl addif br0 veth101.0&lt;br /&gt;
&lt;br /&gt;
{{Note|There will be a delay of about 15 seconds(default for 2.6.18 kernel) while the bridge software runs STP to detect loops and transitions the veth interface to the forwarding state.&lt;br /&gt;
&amp;lt;!-- /sys/class/net/$BR_NAME/bridge/forward_delay in SEC*USER_HZ --&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==== Set up the default route for the VE ====&lt;br /&gt;
 [HN]# vzctl exec 101 ip route add default via 85.86.87.193 dev eth0&lt;br /&gt;
 &lt;br /&gt;
==== (Optional) Add VE↔HN routes ====&lt;br /&gt;
The above configuration provides the following connections:&lt;br /&gt;
* VE X ↔ VE Y (where VE X and VE Y can locate on any OVZ HN)&lt;br /&gt;
* VE   ↔ Internet&lt;br /&gt;
&lt;br /&gt;
Note that&lt;br /&gt;
&lt;br /&gt;
* The accessability of the VE from the HN depends on the local gateway providing NAT(probably - yes)&lt;br /&gt;
&lt;br /&gt;
* The accessability of the HN from the VE depends on the ISP gateway being aware of the local network(probably not)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So to provide VE ↔ HN accessibility despite the gateways' configuration you can add the following routes:&lt;br /&gt;
&lt;br /&gt;
 [HN]# ip route add 85.86.87.195 dev br0&lt;br /&gt;
 [HN]# vzctl exec 101 ip route add 10.0.0.2 dev eth0&lt;br /&gt;
&lt;br /&gt;
=== Resulting OpenVZ Node configuration ===&lt;br /&gt;
[[Image:PrivateIPs_fig2.gif|Resulting OpenVZ Node configuration]]&lt;br /&gt;
&lt;br /&gt;
=== Making the configuration persistent ===&lt;br /&gt;
&lt;br /&gt;
==== Set up a bridge on a HN ====&lt;br /&gt;
This can be done by configuring the &amp;lt;code&amp;gt;ifcfg-*&amp;lt;/code&amp;gt; files located in &amp;lt;code&amp;gt;/etc/sysconfig/network-scripts/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assuming you had a configuration file (e.g. &amp;lt;code&amp;gt;ifcfg-eth0&amp;lt;/code&amp;gt;) like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
IPADDR=10.0.0.2&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=10.0.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To automatically create bridge &amp;lt;code&amp;gt;br0&amp;lt;/code&amp;gt;  you can create &amp;lt;code&amp;gt;ifcfg-br0&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=br0&lt;br /&gt;
TYPE=Bridge&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
IPADDR=10.0.0.2&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=10.0.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and edit &amp;lt;code&amp;gt;ifcfg-eth0&amp;lt;/code&amp;gt; to add the &amp;lt;code&amp;gt;eth0&amp;lt;/code&amp;gt; interface into the bridge &amp;lt;code&amp;gt;br0&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
BRIDGE=br0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Edit the VE's configuration ====&lt;br /&gt;
Add these parameters to the &amp;lt;code&amp;gt;/etc/vz/conf/$VEID.conf&amp;lt;/code&amp;gt; file which will be used during the network configuration:&lt;br /&gt;
* Add/change &amp;lt;code&amp;gt;CONFIG_CUSTOMIZED=&amp;quot;yes&amp;quot;&amp;lt;/code&amp;gt; (indicates that a custom script should be run on a VE start)&lt;br /&gt;
* Add &amp;lt;code&amp;gt;VETH_IP_ADDRESS=&amp;quot;VE IP/MASK&amp;quot;&amp;lt;/code&amp;gt; (a VE can have multiple IPs separated by spaces)&lt;br /&gt;
* Add &amp;lt;code&amp;gt;VE_DEFAULT_GATEWAY=&amp;quot;VE DEFAULT GATEWAY&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
* Add &amp;lt;code&amp;gt;BRIDGEDEV=&amp;quot;BRIDGE NAME&amp;quot;&amp;lt;/code&amp;gt; (a bridge name to which the VE veth interface should be added)&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Network customization section&lt;br /&gt;
CONFIG_CUSTOMIZED=&amp;quot;yes&amp;quot;&lt;br /&gt;
VETH_IP_ADDRESS=&amp;quot;85.86.87.195/26&amp;quot;&lt;br /&gt;
VE_DEFAULT_GATEWAY=&amp;quot;85.86.87.193&amp;quot;&lt;br /&gt;
BRIDGEDEV=&amp;quot;br0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a custom network configuration script ====&lt;br /&gt;
which should be called each time a VE is started (e.g. &amp;lt;code&amp;gt;/usr/sbin/vznetcfg.custom&amp;lt;/code&amp;gt;):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# /usr/sbin/vznetcfg.custom&lt;br /&gt;
# a script to bring up bridged network interfaces (veth's) in a VE&lt;br /&gt;
&lt;br /&gt;
GLOBALCONFIGFILE=/etc/vz/vz.conf&lt;br /&gt;
VECONFIGFILE=/etc/vz/conf/$VEID.conf&lt;br /&gt;
vzctl=/usr/sbin/vzctl&lt;br /&gt;
brctl=/usr/sbin/brctl&lt;br /&gt;
ip=/sbin/ip&lt;br /&gt;
ifconfig=/sbin/ifconfig&lt;br /&gt;
. $GLOBALCONFIGFILE&lt;br /&gt;
. $VECONFIGFILE&lt;br /&gt;
&lt;br /&gt;
NETIF_OPTIONS=`echo $NETIF | sed 's/,/\n/g'`&lt;br /&gt;
for str in $NETIF_OPTIONS; do \&lt;br /&gt;
        # getting 'ifname' parameter value&lt;br /&gt;
        if [[ &amp;quot;$str&amp;quot; =~ &amp;quot;^ifname=&amp;quot; ]]; then&lt;br /&gt;
                # remove the parameter name from the string (along with '=')&lt;br /&gt;
                VEIFNAME=${str#*=};&lt;br /&gt;
        fi&lt;br /&gt;
        # getting 'host_ifname' parameter value&lt;br /&gt;
        if [[ &amp;quot;$str&amp;quot; =~ &amp;quot;^host_ifname=&amp;quot; ]]; then&lt;br /&gt;
                # remove the parameter name from the string (along with '=')&lt;br /&gt;
                VZHOSTIF=${str#*=};&lt;br /&gt;
        fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VETH_IP_ADDRESS&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;According to $CONFIGFILE VE$VEID has no veth IPs configured.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VZHOSTIF&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;According to $CONFIGFILE VE$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;$VEIFNAME&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Corrupted $CONFIGFILE: no 'ifname' defined for host_ifname $VZHOSTIF.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Initializing interface $VZHOSTIF for VE$VEID.&amp;quot;&lt;br /&gt;
$ifconfig $VZHOSTIF 0&lt;br /&gt;
&lt;br /&gt;
VEROUTEDEV=$VZHOSTIF&lt;br /&gt;
&lt;br /&gt;
if [ -n &amp;quot;$BRIDGEDEV&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Adding interface $VZHOSTIF to the bridge $BRIDGEDEV.&amp;quot;&lt;br /&gt;
   VEROUTEDEV=$BRIDGEDEV&lt;br /&gt;
   $brctl addif $BRIDGEDEV $VZHOSTIF&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Up the interface $VEIFNAME link in VE$VEID&lt;br /&gt;
$vzctl exec $VEID $ip link set $VEIFNAME up&lt;br /&gt;
&lt;br /&gt;
for IP in $VETH_IP_ADDRESS; do&lt;br /&gt;
   echo &amp;quot;Adding an IP $IP to the $VEIFNAME for VE$VEID.&amp;quot;&lt;br /&gt;
   $vzctl exec $VEID $ip address add $IP dev $VEIFNAME&lt;br /&gt;
&lt;br /&gt;
   # removing the netmask&lt;br /&gt;
   IP_STRIP=${IP%%/*};&lt;br /&gt;
&lt;br /&gt;
   echo &amp;quot;Adding a route from VE0 to VE$VEID.&amp;quot;&lt;br /&gt;
   $ip route add $IP_STRIP dev $VEROUTEDEV&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
if [ -n &amp;quot;$VE0_IP&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Adding a route from VE$VEID to VE0.&amp;quot;&lt;br /&gt;
   $vzctl exec $VEID $ip route add $VE0_IP dev $VEIFNAME&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ -n &amp;quot;$VE_DEFAULT_GATEWAY&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Setting $VE_DEFAULT_GATEWAY as a default gateway for VE$VEID.&amp;quot;&lt;br /&gt;
   $vzctl exec $VEID \&lt;br /&gt;
        $ip route add default via $VE_DEFAULT_GATEWAY dev $VEIFNAME&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;&amp;lt;small&amp;gt;Note: this script can be easily extended to work for multiple triples &amp;amp;lt;bridge, ip address, veth device&amp;amp;gt;, see http://vireso.blogspot.com/2008/02/2-veth-with-2-brindges-on-openvz-at.html &amp;lt;/small&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Make the script to be run on a VE start ====&lt;br /&gt;
In order to run above script on a VE start create the file &amp;lt;code&amp;gt;/etc/vz/vznet.conf&amp;lt;/code&amp;gt; with the following contents:&lt;br /&gt;
&lt;br /&gt;
 EXTERNAL_SCRIPT=&amp;quot;/usr/sbin/vznetcfg.custom&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{Note|&amp;lt;code&amp;gt;/usr/sbin/vznetcfg.custom&amp;lt;/code&amp;gt; should be executable.(chmod +x /usr/sbin/vznetcfg.custom)}}&lt;br /&gt;
&lt;br /&gt;
==== Setting the route VE → HN ====&lt;br /&gt;
To set up a route from the VE to the HN, the custom script has to get a HN IP (the $VE0_IP variable in the script). There are several ways to specify it:&lt;br /&gt;
&lt;br /&gt;
# Add an entry VE0_IP=&amp;quot;VE0 IP&amp;quot; to the &amp;lt;code&amp;gt;$VEID.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
# Add an entry VE0_IP=&amp;quot;VE0 IP&amp;quot; to the &amp;lt;code&amp;gt;/etc/vz/vz.conf&amp;lt;/code&amp;gt; (the global configuration config file)&lt;br /&gt;
# Implement some smart algorithm to determine the VE0 IP right in the custom network configuration script&lt;br /&gt;
&lt;br /&gt;
Each variant has its pros and cons, nevertheless for HN static IP configuration variant 2 seems to be acceptable (and the most simple).&lt;br /&gt;
&lt;br /&gt;
== An OpenVZ Hardware Node has two Ethernet interfaces ==&lt;br /&gt;
Assuming you have 2 interfaces eth0 and eth1 and want to separate local traffic (10.0.0.0/24) from  external traffic.&lt;br /&gt;
Let's assign eth0 for the external traffic and eth1 for the local one.&lt;br /&gt;
&lt;br /&gt;
If there is no need to make the VE accessible from the HN and vice versa, it's enough to replace 'br0' with 'eth1' in the following steps of the above configuration:&lt;br /&gt;
* Hardware Node configuration → [[Using_private_IPs_for_Hardware_Nodes#Assign_the_IP_to_the_bridge|Assign the IP to the bridge]]&lt;br /&gt;
* Hardware Node configuration → [[Using_private_IPs_for_Hardware_Nodes#Resurrect_the_default_routing|Resurrect the default routing]]&lt;br /&gt;
&lt;br /&gt;
It is nesessary to set a local IP for 'br0' to ensure VE ↔ HN connection availability.&lt;br /&gt;
&lt;br /&gt;
== Putting VEs to different subnetworks ==&lt;br /&gt;
It's enough to set up the correct $VETH_IP_ADDRESS and $VE_DEFAULT_GATEWAY values in the &lt;br /&gt;
[[Using_private_IPs_for_Hardware_Nodes#Edit_the_VE.27s_configuration|above 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;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>SergeyIvanov</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=4122</id>
		<title>Using private IPs for Hardware Nodes</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=4122"/>
		<updated>2008-02-10T17:43:59Z</updated>

		<summary type="html">&lt;p&gt;SergeyIvanov: /* An OpenVZ Hardware Node has two Ethernet interfaces */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes how to assign public IPs to VEs running on OVZ Hardware Nodes in case you have a following network topology:&lt;br /&gt;
&lt;br /&gt;
[[Image:PrivateIPs_fig1.gif|An initial network topology]]&lt;br /&gt;
&lt;br /&gt;
== Prerequisites ==&lt;br /&gt;
This configuration was tested on a RHEL5 OpenVZ Hardware Node and a VE based on a Fedora Core 5 template.&lt;br /&gt;
Other host OSs and templates might require some configuration changes, please add corresponding OS specific changes if you've faced any.&lt;br /&gt;
&lt;br /&gt;
This article assumes the presence of 'brctl', 'ip' and 'ifconfig' utils. You may need to install missing packages like 'bridge-utils'/'iproute'/'net-tools' or others which contain those utilities.&lt;br /&gt;
&lt;br /&gt;
This article assumes you have already [[Quick installation|installed OpenVZ]], prepared the [[OS template cache]](s) and have [[Basic_operations_in_OpenVZ_environment|VE(s) created]]. If not, follow the links to perform the steps needed.&lt;br /&gt;
{{Note|don't assign an IP after VE creation.}}&lt;br /&gt;
&lt;br /&gt;
== An OVZ Hardware Node has the only one Ethernet interface ==&lt;br /&gt;
(assume eth0)&lt;br /&gt;
&lt;br /&gt;
=== Hardware Node configuration ===&lt;br /&gt;
&lt;br /&gt;
==== Create a bridge device ====&lt;br /&gt;
 [HN]# brctl addbr br0&lt;br /&gt;
&lt;br /&gt;
==== Remove an IP from eth0 interface ====&lt;br /&gt;
 [HN]# ifconfig eth0 0&lt;br /&gt;
&lt;br /&gt;
==== Add eth0 interface into the bridge ====&lt;br /&gt;
 [HN]# brctl addif br0 eth0&lt;br /&gt;
 &lt;br /&gt;
==== Assign the IP to the bridge ====&lt;br /&gt;
(the same that was assigned on eth0 earlier)&lt;br /&gt;
 [HN]# ifconfig br0 10.0.0.2/24&lt;br /&gt;
&lt;br /&gt;
==== Resurrect the default routing ====&lt;br /&gt;
 [HN]# ip route add default via 10.0.0.1 dev br0&lt;br /&gt;
 &lt;br /&gt;
{{Warning|if you are '''configuring''' the node '''remotely''' you '''must''' prepare a '''script''' with the above commands and run it in background with the redirected output or you'll '''lose the access''' to the Node.}}&lt;br /&gt;
&lt;br /&gt;
==== A script example ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[HN]# cat /tmp/br_add &lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
brctl addbr br0&lt;br /&gt;
ifconfig eth0 0 &lt;br /&gt;
brctl addif br0 eth0 &lt;br /&gt;
ifconfig br0 10.0.0.2/24 &lt;br /&gt;
ip route add default via 10.0.0.1 dev br0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 [HN]# /tmp/br_add &amp;gt;/dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
=== VE configuration ===&lt;br /&gt;
&lt;br /&gt;
==== Start a VE ====&lt;br /&gt;
 [HN]# vzctl start 101&lt;br /&gt;
&lt;br /&gt;
==== Add a [[Virtual_Ethernet_device|veth interface]] to the VE ====&lt;br /&gt;
 [HN]# vzctl set 101 --netif_add eth0 --save&lt;br /&gt;
&lt;br /&gt;
==== Set up an IP to the newly created VE's veth interface ====&lt;br /&gt;
 [HN]# vzctl exec 101 ifconfig eth0 85.86.87.195/26&lt;br /&gt;
 &lt;br /&gt;
==== Add the VE's veth interface to the bridge ====&lt;br /&gt;
 [HN]# brctl addif br0 veth101.0&lt;br /&gt;
&lt;br /&gt;
{{Note|There will be a delay of about 15 seconds(default for 2.6.18 kernel) while the bridge software runs STP to detect loops and transitions the veth interface to the forwarding state.&lt;br /&gt;
&amp;lt;!-- /sys/class/net/$BR_NAME/bridge/forward_delay in SEC*USER_HZ --&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==== Set up the default route for the VE ====&lt;br /&gt;
 [HN]# vzctl exec 101 ip route add default via 85.86.87.193 dev eth0&lt;br /&gt;
 &lt;br /&gt;
==== (Optional) Add VE↔HN routes ====&lt;br /&gt;
The above configuration provides the following connections:&lt;br /&gt;
* VE X ↔ VE Y (where VE X and VE Y can locate on any OVZ HN)&lt;br /&gt;
* VE   ↔ Internet&lt;br /&gt;
&lt;br /&gt;
Note that&lt;br /&gt;
&lt;br /&gt;
* The accessability of the VE from the HN depends on the local gateway providing NAT(probably - yes)&lt;br /&gt;
&lt;br /&gt;
* The accessability of the HN from the VE depends on the ISP gateway being aware of the local network(probably not)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So to provide VE ↔ HN accessibility despite the gateways' configuration you can add the following routes:&lt;br /&gt;
&lt;br /&gt;
 [HN]# ip route add 85.86.87.195 dev br0&lt;br /&gt;
 [HN]# vzctl exec 101 ip route add 10.0.0.2 dev eth0&lt;br /&gt;
&lt;br /&gt;
=== Resulting OpenVZ Node configuration ===&lt;br /&gt;
[[Image:PrivateIPs_fig2.gif|Resulting OpenVZ Node configuration]]&lt;br /&gt;
&lt;br /&gt;
=== Making the configuration persistent ===&lt;br /&gt;
&lt;br /&gt;
==== Set up a bridge on a HN ====&lt;br /&gt;
This can be done by configuring the &amp;lt;code&amp;gt;ifcfg-*&amp;lt;/code&amp;gt; files located in &amp;lt;code&amp;gt;/etc/sysconfig/network-scripts/&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Assuming you had a configuration file (e.g. &amp;lt;code&amp;gt;ifcfg-eth0&amp;lt;/code&amp;gt;) like:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
IPADDR=10.0.0.2&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=10.0.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To automatically create bridge &amp;lt;code&amp;gt;br0&amp;lt;/code&amp;gt;  you can create &amp;lt;code&amp;gt;ifcfg-br0&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=br0&lt;br /&gt;
TYPE=Bridge&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
IPADDR=10.0.0.2&lt;br /&gt;
NETMASK=255.255.255.0&lt;br /&gt;
GATEWAY=10.0.0.1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and edit &amp;lt;code&amp;gt;ifcfg-eth0&amp;lt;/code&amp;gt; to add the &amp;lt;code&amp;gt;eth0&amp;lt;/code&amp;gt; interface into the bridge &amp;lt;code&amp;gt;br0&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
BRIDGE=br0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Edit the VE's configuration ====&lt;br /&gt;
Add these parameters to the &amp;lt;code&amp;gt;/etc/vz/conf/$VEID.conf&amp;lt;/code&amp;gt; file which will be used during the network configuration:&lt;br /&gt;
* Add/change &amp;lt;code&amp;gt;CONFIG_CUSTOMIZED=&amp;quot;yes&amp;quot;&amp;lt;/code&amp;gt; (indicates that a custom script should be run on a VE start)&lt;br /&gt;
* Add &amp;lt;code&amp;gt;VETH_IP_ADDRESS=&amp;quot;VE IP/MASK&amp;quot;&amp;lt;/code&amp;gt; (a VE can have multiple IPs separated by spaces)&lt;br /&gt;
* Add &amp;lt;code&amp;gt;VE_DEFAULT_GATEWAY=&amp;quot;VE DEFAULT GATEWAY&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
* Add &amp;lt;code&amp;gt;BRIDGEDEV=&amp;quot;BRIDGE NAME&amp;quot;&amp;lt;/code&amp;gt; (a bridge name to which the VE veth interface should be added)&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# Network customization section&lt;br /&gt;
CONFIG_CUSTOMIZED=&amp;quot;yes&amp;quot;&lt;br /&gt;
VETH_IP_ADDRESS=&amp;quot;85.86.87.195/26&amp;quot;&lt;br /&gt;
VE_DEFAULT_GATEWAY=&amp;quot;85.86.87.193&amp;quot;&lt;br /&gt;
BRIDGEDEV=&amp;quot;br0&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Create a custom network configuration script ====&lt;br /&gt;
which should be called each time a VE is started (e.g. &amp;lt;code&amp;gt;/usr/sbin/vznetcfg.custom&amp;lt;/code&amp;gt;):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
# /usr/sbin/vznetcfg.custom&lt;br /&gt;
# a script to bring up bridged network interfaces (veth's) in a VE&lt;br /&gt;
&lt;br /&gt;
GLOBALCONFIGFILE=/etc/vz/vz.conf&lt;br /&gt;
VECONFIGFILE=/etc/vz/conf/$VEID.conf&lt;br /&gt;
vzctl=/usr/sbin/vzctl&lt;br /&gt;
brctl=/usr/sbin/brctl&lt;br /&gt;
ip=/sbin/ip&lt;br /&gt;
ifconfig=/sbin/ifconfig&lt;br /&gt;
. $GLOBALCONFIGFILE&lt;br /&gt;
. $VECONFIGFILE&lt;br /&gt;
&lt;br /&gt;
NETIF_OPTIONS=`echo $NETIF | sed 's/,/\n/g'`&lt;br /&gt;
for str in $NETIF_OPTIONS; do \&lt;br /&gt;
        # getting 'ifname' parameter value&lt;br /&gt;
        if [[ &amp;quot;$str&amp;quot; =~ &amp;quot;^ifname=&amp;quot; ]]; then&lt;br /&gt;
                # remove the parameter name from the string (along with '=')&lt;br /&gt;
                VEIFNAME=${str#*=};&lt;br /&gt;
        fi&lt;br /&gt;
        # getting 'host_ifname' parameter value&lt;br /&gt;
        if [[ &amp;quot;$str&amp;quot; =~ &amp;quot;^host_ifname=&amp;quot; ]]; then&lt;br /&gt;
                # remove the parameter name from the string (along with '=')&lt;br /&gt;
                VZHOSTIF=${str#*=};&lt;br /&gt;
        fi&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VETH_IP_ADDRESS&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;According to $CONFIGFILE VE$VEID has no veth IPs configured.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ ! -n &amp;quot;$VZHOSTIF&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;According to $CONFIGFILE VE$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;$VEIFNAME&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Corrupted $CONFIGFILE: no 'ifname' defined for host_ifname $VZHOSTIF.&amp;quot;&lt;br /&gt;
   exit 1&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
echo &amp;quot;Initializing interface $VZHOSTIF for VE$VEID.&amp;quot;&lt;br /&gt;
$ifconfig $VZHOSTIF 0&lt;br /&gt;
&lt;br /&gt;
VEROUTEDEV=$VZHOSTIF&lt;br /&gt;
&lt;br /&gt;
if [ -n &amp;quot;$BRIDGEDEV&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Adding interface $VZHOSTIF to the bridge $BRIDGEDEV.&amp;quot;&lt;br /&gt;
   VEROUTEDEV=$BRIDGEDEV&lt;br /&gt;
   $brctl addif $BRIDGEDEV $VZHOSTIF&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
# Up the interface $VEIFNAME link in VE$VEID&lt;br /&gt;
$vzctl exec $VEID $ip link set $VEIFNAME up&lt;br /&gt;
&lt;br /&gt;
for IP in $VETH_IP_ADDRESS; do&lt;br /&gt;
   echo &amp;quot;Adding an IP $IP to the $VEIFNAME for VE$VEID.&amp;quot;&lt;br /&gt;
   $vzctl exec $VEID $ip address add $IP dev $VEIFNAME&lt;br /&gt;
&lt;br /&gt;
   # removing the netmask&lt;br /&gt;
   IP_STRIP=${IP%%/*};&lt;br /&gt;
&lt;br /&gt;
   echo &amp;quot;Adding a route from VE0 to VE$VEID.&amp;quot;&lt;br /&gt;
   $ip route add $IP_STRIP dev $VEROUTEDEV&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
if [ -n &amp;quot;$VE0_IP&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Adding a route from VE$VEID to VE0.&amp;quot;&lt;br /&gt;
   $vzctl exec $VEID $ip route add $VE0_IP dev $VEIFNAME&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ -n &amp;quot;$VE_DEFAULT_GATEWAY&amp;quot; ]; then&lt;br /&gt;
   echo &amp;quot;Setting $VE_DEFAULT_GATEWAY as a default gateway for VE$VEID.&amp;quot;&lt;br /&gt;
   $vzctl exec $VEID \&lt;br /&gt;
        $ip route add default via $VE_DEFAULT_GATEWAY dev $VEIFNAME&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
exit 0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Make the script to be run on a VE start ====&lt;br /&gt;
In order to run above script on a VE start create the file &amp;lt;code&amp;gt;/etc/vz/vznet.conf&amp;lt;/code&amp;gt; with the following contents:&lt;br /&gt;
&lt;br /&gt;
 EXTERNAL_SCRIPT=&amp;quot;/usr/sbin/vznetcfg.custom&amp;quot;&lt;br /&gt;
&lt;br /&gt;
{{Note|&amp;lt;code&amp;gt;/usr/sbin/vznetcfg.custom&amp;lt;/code&amp;gt; should be executable.(chmod +x /usr/sbin/vznetcfg.custom)}}&lt;br /&gt;
&lt;br /&gt;
==== Setting the route VE → HN ====&lt;br /&gt;
To set up a route from the VE to the HN, the custom script has to get a HN IP (the $VE0_IP variable in the script). There are several ways to specify it:&lt;br /&gt;
&lt;br /&gt;
# Add an entry VE0_IP=&amp;quot;VE0 IP&amp;quot; to the &amp;lt;code&amp;gt;$VEID.conf&amp;lt;/code&amp;gt;&lt;br /&gt;
# Add an entry VE0_IP=&amp;quot;VE0 IP&amp;quot; to the &amp;lt;code&amp;gt;/etc/vz/vz.conf&amp;lt;/code&amp;gt; (the global configuration config file)&lt;br /&gt;
# Implement some smart algorithm to determine the VE0 IP right in the custom network configuration script&lt;br /&gt;
&lt;br /&gt;
Each variant has its pros and cons, nevertheless for HN static IP configuration variant 2 seems to be acceptable (and the most simple).&lt;br /&gt;
&lt;br /&gt;
== An OpenVZ Hardware Node has two Ethernet interfaces ==&lt;br /&gt;
Assuming you have 2 interfaces eth0 and eth1 and want to separate local traffic (10.0.0.0/24) from  external traffic.&lt;br /&gt;
Let's assign eth0 for the external traffic and eth1 for the local one.&lt;br /&gt;
&lt;br /&gt;
If there is no need to make the VE accessible from the HN and vice versa, it's enough to replace 'br0' and 'eth0' with 'br1' and 'eth1' in the following steps of the above configuration:&lt;br /&gt;
* Hardware Node configuration → [[Using_private_IPs_for_Hardware_Nodes#Assign_the_IP_to_the_bridge|Assign the IP to the bridge]]&lt;br /&gt;
* Hardware Node configuration → [[Using_private_IPs_for_Hardware_Nodes#Resurrect_the_default_routing|Resurrect the default routing]]&lt;br /&gt;
&lt;br /&gt;
It is nesessary to set a local IP for 'br0' to ensure VE ↔ HN connection availability.&lt;br /&gt;
&lt;br /&gt;
== Putting VEs to different subnetworks ==&lt;br /&gt;
It's enough to set up the correct $VETH_IP_ADDRESS and $VE_DEFAULT_GATEWAY values in the &lt;br /&gt;
[[Using_private_IPs_for_Hardware_Nodes#Edit_the_VE.27s_configuration|above 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;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>SergeyIvanov</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Using_gdb&amp;diff=3010</id>
		<title>Using gdb</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Using_gdb&amp;diff=3010"/>
		<updated>2007-04-13T11:30:47Z</updated>

		<summary type="html">&lt;p&gt;SergeyIvanov: using gdb or valgrind for threaded programs: upgrade kernel&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;If you have problems with using gdb or valgrind with threaded programs (like that of http://bugzilla.openvz.org/show_bug.cgi?id=487), just upgrade to ovzkernel-2.6.18. &lt;br /&gt;
&lt;br /&gt;
[[Category: Troubleshooting]]&lt;/div&gt;</summary>
		<author><name>SergeyIvanov</name></author>
		
	</entry>
</feed>