<?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=Bwian</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=Bwian"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/Bwian"/>
	<updated>2026-05-14T16:19:08Z</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=3678</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=3678"/>
		<updated>2007-11-30T11:35:34Z</updated>

		<summary type="html">&lt;p&gt;Bwian: /* An OpenVZ Hardware Node has two Ethernet interfaces */ readability&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 venet 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' 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>Bwian</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=3677</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=3677"/>
		<updated>2007-11-30T11:31:44Z</updated>

		<summary type="html">&lt;p&gt;Bwian: /* Setting the route VE → HN */ readability&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 venet 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;
Assume you have 2 interfaces eth0 and eth1 and want to separate local traffic (10.0.0.0/24) from the 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 aim to make VE accessible from HN and vice versa, it's enough to replace 'br0' with 'eth1' in the following steps of 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;
For the VE ↔ HN connections availability it is nesessary to set an IP (local) to the 'br0'.&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>Bwian</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=3676</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=3676"/>
		<updated>2007-11-30T11:29:16Z</updated>

		<summary type="html">&lt;p&gt;Bwian: /* Make the script to be run on a VE start */ readability&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 venet 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 VE to HN the custom script has to get a HN IP (the $VE0_IP variable in the script). There can be different approaches 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;
Every 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;
Assume you have 2 interfaces eth0 and eth1 and want to separate local traffic (10.0.0.0/24) from the 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 aim to make VE accessible from HN and vice versa, it's enough to replace 'br0' with 'eth1' in the following steps of 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;
For the VE ↔ HN connections availability it is nesessary to set an IP (local) to the 'br0'.&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>Bwian</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=3675</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=3675"/>
		<updated>2007-11-30T11:27:25Z</updated>

		<summary type="html">&lt;p&gt;Bwian: /* Create a custom network configuration script */ readability&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 venet 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 &amp;lt;code&amp;gt;/etc/vz/vznet.conf&amp;lt;/code&amp;gt; file 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; file should be executable.}}&lt;br /&gt;
&lt;br /&gt;
==== Setting the route VE → HN ====&lt;br /&gt;
To set up a route from VE to HN the custom script has to get a HN IP (the $VE0_IP variable in the script). There can be different approaches 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;
Every 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;
Assume you have 2 interfaces eth0 and eth1 and want to separate local traffic (10.0.0.0/24) from the 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 aim to make VE accessible from HN and vice versa, it's enough to replace 'br0' with 'eth1' in the following steps of 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;
For the VE ↔ HN connections availability it is nesessary to set an IP (local) to the 'br0'.&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>Bwian</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=3674</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=3674"/>
		<updated>2007-11-30T11:26:25Z</updated>

		<summary type="html">&lt;p&gt;Bwian: /* Edit the VE's configuration */ readability&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 venet 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 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 &amp;lt;code&amp;gt;/etc/vz/vznet.conf&amp;lt;/code&amp;gt; file 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; file should be executable.}}&lt;br /&gt;
&lt;br /&gt;
==== Setting the route VE → HN ====&lt;br /&gt;
To set up a route from VE to HN the custom script has to get a HN IP (the $VE0_IP variable in the script). There can be different approaches 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;
Every 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;
Assume you have 2 interfaces eth0 and eth1 and want to separate local traffic (10.0.0.0/24) from the 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 aim to make VE accessible from HN and vice versa, it's enough to replace 'br0' with 'eth1' in the following steps of 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;
For the VE ↔ HN connections availability it is nesessary to set an IP (local) to the 'br0'.&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>Bwian</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=3673</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=3673"/>
		<updated>2007-11-30T11:24:52Z</updated>

		<summary type="html">&lt;p&gt;Bwian: /* Set up a bridge on a HN */ readability&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 venet 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 some parameters to the &amp;lt;code&amp;gt;/etc/vz/conf/$VEID.conf&amp;lt;/code&amp;gt; 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 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 &amp;lt;code&amp;gt;/etc/vz/vznet.conf&amp;lt;/code&amp;gt; file 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; file should be executable.}}&lt;br /&gt;
&lt;br /&gt;
==== Setting the route VE → HN ====&lt;br /&gt;
To set up a route from VE to HN the custom script has to get a HN IP (the $VE0_IP variable in the script). There can be different approaches 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;
Every 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;
Assume you have 2 interfaces eth0 and eth1 and want to separate local traffic (10.0.0.0/24) from the 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 aim to make VE accessible from HN and vice versa, it's enough to replace 'br0' with 'eth1' in the following steps of 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;
For the VE ↔ HN connections availability it is nesessary to set an IP (local) to the 'br0'.&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>Bwian</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=3672</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=3672"/>
		<updated>2007-11-30T11:15:15Z</updated>

		<summary type="html">&lt;p&gt;Bwian: /* (Optional) Add VE↔HN routes */ readability&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 venet 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 &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 make bridge &amp;lt;code&amp;gt;br0&amp;lt;/code&amp;gt; automatically created 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; file to add &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 some parameters to the &amp;lt;code&amp;gt;/etc/vz/conf/$VEID.conf&amp;lt;/code&amp;gt; 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 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 &amp;lt;code&amp;gt;/etc/vz/vznet.conf&amp;lt;/code&amp;gt; file 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; file should be executable.}}&lt;br /&gt;
&lt;br /&gt;
==== Setting the route VE → HN ====&lt;br /&gt;
To set up a route from VE to HN the custom script has to get a HN IP (the $VE0_IP variable in the script). There can be different approaches 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;
Every 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;
Assume you have 2 interfaces eth0 and eth1 and want to separate local traffic (10.0.0.0/24) from the 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 aim to make VE accessible from HN and vice versa, it's enough to replace 'br0' with 'eth1' in the following steps of 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;
For the VE ↔ HN connections availability it is nesessary to set an IP (local) to the 'br0'.&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>Bwian</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=3671</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=3671"/>
		<updated>2007-11-30T10:49:45Z</updated>

		<summary type="html">&lt;p&gt;Bwian: /* Add the VE's veth interface to the bridge */ readability&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 venet 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 configuration above provides following connections available:&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;
* A VE accessibility from the HN depends on if the local gateway provides NAT or not (probably - yes).&lt;br /&gt;
* A HN accessibility from a VE depends on if the ISP gateway is aware about the local network addresses (most probably - no).&lt;br /&gt;
&lt;br /&gt;
So to provide VE ↔ HN accessibility despite the gateways' configuration you can add the following route rules:&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 &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 make bridge &amp;lt;code&amp;gt;br0&amp;lt;/code&amp;gt; automatically created 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; file to add &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 some parameters to the &amp;lt;code&amp;gt;/etc/vz/conf/$VEID.conf&amp;lt;/code&amp;gt; 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 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 &amp;lt;code&amp;gt;/etc/vz/vznet.conf&amp;lt;/code&amp;gt; file 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; file should be executable.}}&lt;br /&gt;
&lt;br /&gt;
==== Setting the route VE → HN ====&lt;br /&gt;
To set up a route from VE to HN the custom script has to get a HN IP (the $VE0_IP variable in the script). There can be different approaches 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;
Every 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;
Assume you have 2 interfaces eth0 and eth1 and want to separate local traffic (10.0.0.0/24) from the 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 aim to make VE accessible from HN and vice versa, it's enough to replace 'br0' with 'eth1' in the following steps of 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;
For the VE ↔ HN connections availability it is nesessary to set an IP (local) to the 'br0'.&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>Bwian</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Using_private_IPs_for_Hardware_Nodes&amp;diff=3670</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=3670"/>
		<updated>2007-11-30T10:37:46Z</updated>

		<summary type="html">&lt;p&gt;Bwian: /* Prerequisites */  grammar/readability, minor edit&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|veth interface will work as expected only after it is turned by the bridge into the forwarding state after some delay.&lt;br /&gt;
In 2.6.18 kernel it is 15 seconds by default.&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 configuration above provides following connections available:&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;
* A VE accessibility from the HN depends on if the local gateway provides NAT or not (probably - yes).&lt;br /&gt;
* A HN accessibility from a VE depends on if the ISP gateway is aware about the local network addresses (most probably - no).&lt;br /&gt;
&lt;br /&gt;
So to provide VE ↔ HN accessibility despite the gateways' configuration you can add the following route rules:&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 &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 make bridge &amp;lt;code&amp;gt;br0&amp;lt;/code&amp;gt; automatically created 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; file to add &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 some parameters to the &amp;lt;code&amp;gt;/etc/vz/conf/$VEID.conf&amp;lt;/code&amp;gt; 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 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 &amp;lt;code&amp;gt;/etc/vz/vznet.conf&amp;lt;/code&amp;gt; file 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; file should be executable.}}&lt;br /&gt;
&lt;br /&gt;
==== Setting the route VE → HN ====&lt;br /&gt;
To set up a route from VE to HN the custom script has to get a HN IP (the $VE0_IP variable in the script). There can be different approaches 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;
Every 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;
Assume you have 2 interfaces eth0 and eth1 and want to separate local traffic (10.0.0.0/24) from the 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 aim to make VE accessible from HN and vice versa, it's enough to replace 'br0' with 'eth1' in the following steps of 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;
For the VE ↔ HN connections availability it is nesessary to set an IP (local) to the 'br0'.&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>Bwian</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Bonding&amp;diff=3424</id>
		<title>Bonding</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Bonding&amp;diff=3424"/>
		<updated>2007-09-04T06:46:33Z</updated>

		<summary type="html">&lt;p&gt;Bwian: /* Modify eth0 and eth1 config files */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Linux allows binding multiple network interfaces into a single channel/NIC.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The Linux bonding driver provides a method for aggregating&lt;br /&gt;
multiple network interfaces into a single logical &amp;quot;bonded&amp;quot; interface.&lt;br /&gt;
The behavior of the bonded interfaces depends upon the mode; generally&lt;br /&gt;
speaking, modes provide either hot standby or load balancing services.&lt;br /&gt;
Additionally, link integrity monitoring may be performed.&lt;br /&gt;
&lt;br /&gt;
== Setting up bounding on a RHEL/CentOS 4 system ==&lt;br /&gt;
&lt;br /&gt;
===Create a bond0 configuration file===&lt;br /&gt;
&lt;br /&gt;
Red Hat Linux stores network configuration in /etc/sysconfig/network-scripts/ directory. First, you need to create bond0 config file:&lt;br /&gt;
&lt;br /&gt;
 # vi /etc/sysconfig/network-scripts/ifcfg-bond0&lt;br /&gt;
&lt;br /&gt;
Append following lines to it:&lt;br /&gt;
&lt;br /&gt;
====In case of static IP====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=bond0&lt;br /&gt;
IPADDR=x.x.x.x&lt;br /&gt;
NETWORK=y.y.y.y&lt;br /&gt;
NETMASK=z.z.z.z&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
x.x.x.x is an IP address of HW.   &lt;br /&gt;
&lt;br /&gt;
y.y.y.y is an Network address of HW.  &lt;br /&gt;
&lt;br /&gt;
z.z.z.z is an net mask address of HW (usually 255.255.255.0).&lt;br /&gt;
&lt;br /&gt;
Replace above IP data with your actual IP address. Save file and exit to shell prompt.&lt;br /&gt;
&lt;br /&gt;
====In case of DHCP====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=bond0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Modify eth0 and eth1 config files===&lt;br /&gt;
&lt;br /&gt;
Open both configurations using vi (text editor) and make sure the file reads as follows for interface eth0 &lt;br /&gt;
&lt;br /&gt;
 # vi /etc/sysconfig/network-scripts/ifcfg-eth0&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
USERCTL=no&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open the eth1 configuration file using vi :&lt;br /&gt;
&lt;br /&gt;
 vi /etc/sysconfig/network-scripts/ifcfg-eth1&lt;br /&gt;
&lt;br /&gt;
Make sure the file reads as follows for interface eth1:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth1&lt;br /&gt;
USERCTL=no&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Save the file and exit to shell prompt.&lt;br /&gt;
&lt;br /&gt;
=== Load bond driver/module ===&lt;br /&gt;
Make sure the bonding module is loaded before the channel-bonding interface (bond0) is brought up. You need to modify the kernel modules configuration file:&lt;br /&gt;
&lt;br /&gt;
 # vi /etc/modprobe.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias bond0 bonding&lt;br /&gt;
options bond0 miimon=100&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can learn more about bonding options in the kernel source documentation file  &amp;quot;Documentation/networking/bonding.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Test the configuration ===&lt;br /&gt;
First, load the bonding module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# modprobe bonding&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Restart networking service in order to up bond0 interface:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# service network restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check proc info:&lt;br /&gt;
&lt;br /&gt;
 # cat /proc/net/bonding/bond0 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Ethernet Channel Bonding Driver: v2.6.3 (June 8, 2005)&lt;br /&gt;
&lt;br /&gt;
Bonding Mode: load balancing (round-robin)&lt;br /&gt;
MII Status: up&lt;br /&gt;
MII Polling Interval (ms): 0&lt;br /&gt;
Up Delay (ms): 0&lt;br /&gt;
Down Delay (ms): 0&lt;br /&gt;
&lt;br /&gt;
Slave Interface: eth0&lt;br /&gt;
MII Status: up&lt;br /&gt;
Link Failure Count: 0&lt;br /&gt;
Permanent HW addr: 00:0c:29:07:d4:c3&lt;br /&gt;
&lt;br /&gt;
Slave Interface: eth1&lt;br /&gt;
MII Status: up&lt;br /&gt;
Link Failure Count: 0&lt;br /&gt;
Permanent HW addr: 00:0c:29:07:d4:cd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
List all interfaces: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#ip a&lt;br /&gt;
&lt;br /&gt;
2: lo: &amp;lt;LOOPBACK,UP&amp;gt; mtu 16436 qdisc noqueue &lt;br /&gt;
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00&lt;br /&gt;
    inet 127.0.0.1/8 brd 127.255.255.255 scope host lo&lt;br /&gt;
4: bond0: &amp;lt;BROADCAST,MULTICAST,MASTER,UP&amp;gt; mtu 1500 qdisc noqueue &lt;br /&gt;
    link/ether 00:0c:29:73:26:19 brd ff:ff:ff:ff:ff:ff&lt;br /&gt;
    inet 10.17.3.25/16 brd 10.17.255.255 scope global bond0&lt;br /&gt;
6: eth0: &amp;lt;BROADCAST,MULTICAST,SLAVE,UP&amp;gt; mtu 1500 qdisc pfifo_fast master bond0 qlen 1000&lt;br /&gt;
    link/ether 00:0c:29:73:26:19 brd ff:ff:ff:ff:ff:ff&lt;br /&gt;
8: eth1: &amp;lt;BROADCAST,MULTICAST,SLAVE,UP&amp;gt; mtu 1500 qdisc pfifo_fast master bond0 qlen 1000&lt;br /&gt;
    link/ether 00:0c:29:73:26:19 brd ff:ff:ff:ff:ff:ff&lt;br /&gt;
1: venet0: &amp;lt;BROADCAST,POINTOPOINT,NOARP,UP&amp;gt; mtu 1500 qdisc noqueue &lt;br /&gt;
    link/void&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
Route:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ip r&lt;br /&gt;
&lt;br /&gt;
10.17.0.0/16 dev bond0  proto kernel  scope link  src 10.17.3.25 &lt;br /&gt;
169.254.0.0/16 dev bond0  scope link &lt;br /&gt;
default via 10.17.0.1 dev bond0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==  Traffic shaping ==&lt;br /&gt;
=== Virtuozzo traffic shaping tools ===&lt;br /&gt;
Just replace old netdev to new bonding device (bond0)  &lt;br /&gt;
&lt;br /&gt;
vi /etc/sysconfig/vz&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Network traffic parameters&lt;br /&gt;
TRAFFIC_SHAPING=yes&lt;br /&gt;
BANDWIDTH=&amp;quot;bond0:102400&amp;quot;&lt;br /&gt;
TOTALRATE=&amp;quot;bond0:1:4096&amp;quot;&lt;br /&gt;
RATE=&amp;quot;bond0:1:8&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and do the rest as usuall&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# vzctl set $veid --ratebound $bound --rate $rif:$class:$rate --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Traffic shaping with tc ===&lt;br /&gt;
Where is no specifics here, see [[Traffic shaping with tc]].&lt;br /&gt;
&lt;br /&gt;
As a result in: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ip a s  bond0&lt;br /&gt;
4: bond0: &amp;lt;BROADCAST,MULTICAST,MASTER,UP&amp;gt; mtu 1500 qdisc cbq &lt;br /&gt;
##NOTE:Class Based Queueing tc was added          ^^^^^^^^^^  &lt;br /&gt;
    link/ether 00:0c:29:07:d4:c3 brd ff:ff:ff:ff:ff:ff&lt;br /&gt;
    inet 10.17.3.41/16 brd 10.17.255.255 scope global bond0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>Bwian</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Bonding&amp;diff=3423</id>
		<title>Bonding</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Bonding&amp;diff=3423"/>
		<updated>2007-09-04T06:44:20Z</updated>

		<summary type="html">&lt;p&gt;Bwian: /* Load bond driver/module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Linux allows binding multiple network interfaces into a single channel/NIC.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The Linux bonding driver provides a method for aggregating&lt;br /&gt;
multiple network interfaces into a single logical &amp;quot;bonded&amp;quot; interface.&lt;br /&gt;
The behavior of the bonded interfaces depends upon the mode; generally&lt;br /&gt;
speaking, modes provide either hot standby or load balancing services.&lt;br /&gt;
Additionally, link integrity monitoring may be performed.&lt;br /&gt;
&lt;br /&gt;
== Setting up bounding on a RHEL/CentOS 4 system ==&lt;br /&gt;
&lt;br /&gt;
===Create a bond0 configuration file===&lt;br /&gt;
&lt;br /&gt;
Red Hat Linux stores network configuration in /etc/sysconfig/network-scripts/ directory. First, you need to create bond0 config file:&lt;br /&gt;
&lt;br /&gt;
 # vi /etc/sysconfig/network-scripts/ifcfg-bond0&lt;br /&gt;
&lt;br /&gt;
Append following lines to it:&lt;br /&gt;
&lt;br /&gt;
====In case of static IP====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=bond0&lt;br /&gt;
IPADDR=x.x.x.x&lt;br /&gt;
NETWORK=y.y.y.y&lt;br /&gt;
NETMASK=z.z.z.z&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
x.x.x.x is an IP address of HW.   &lt;br /&gt;
&lt;br /&gt;
y.y.y.y is an Network address of HW.  &lt;br /&gt;
&lt;br /&gt;
z.z.z.z is an net mask address of HW (usually 255.255.255.0).&lt;br /&gt;
&lt;br /&gt;
Replace above IP data with your actual IP address. Save file and exit to shell prompt.&lt;br /&gt;
&lt;br /&gt;
====In case of DHCP====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=bond0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Modify eth0 and eth1 config files===&lt;br /&gt;
&lt;br /&gt;
Open both configuration using vi text editor and make sure file read as follows for eth0 interface&lt;br /&gt;
&lt;br /&gt;
 # vi /etc/sysconfig/network-scripts/ifcfg-eth0&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
USERCTL=no&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open eth1 configuration file using vi text editor:&lt;br /&gt;
&lt;br /&gt;
 vi /etc/sysconfig/network-scripts/ifcfg-eth1&lt;br /&gt;
&lt;br /&gt;
Make sure file read as follows for eth1 interface:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth1&lt;br /&gt;
USERCTL=no&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Save file and exit to shell prompt.&lt;br /&gt;
&lt;br /&gt;
=== Load bond driver/module ===&lt;br /&gt;
Make sure the bonding module is loaded before the channel-bonding interface (bond0) is brought up. You need to modify the kernel modules configuration file:&lt;br /&gt;
&lt;br /&gt;
 # vi /etc/modprobe.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias bond0 bonding&lt;br /&gt;
options bond0 miimon=100&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can learn more about bonding options in the kernel source documentation file  &amp;quot;Documentation/networking/bonding.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Test the configuration ===&lt;br /&gt;
First, load the bonding module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# modprobe bonding&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Restart networking service in order to up bond0 interface:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# service network restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check proc info:&lt;br /&gt;
&lt;br /&gt;
 # cat /proc/net/bonding/bond0 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Ethernet Channel Bonding Driver: v2.6.3 (June 8, 2005)&lt;br /&gt;
&lt;br /&gt;
Bonding Mode: load balancing (round-robin)&lt;br /&gt;
MII Status: up&lt;br /&gt;
MII Polling Interval (ms): 0&lt;br /&gt;
Up Delay (ms): 0&lt;br /&gt;
Down Delay (ms): 0&lt;br /&gt;
&lt;br /&gt;
Slave Interface: eth0&lt;br /&gt;
MII Status: up&lt;br /&gt;
Link Failure Count: 0&lt;br /&gt;
Permanent HW addr: 00:0c:29:07:d4:c3&lt;br /&gt;
&lt;br /&gt;
Slave Interface: eth1&lt;br /&gt;
MII Status: up&lt;br /&gt;
Link Failure Count: 0&lt;br /&gt;
Permanent HW addr: 00:0c:29:07:d4:cd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
List all interfaces: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#ip a&lt;br /&gt;
&lt;br /&gt;
2: lo: &amp;lt;LOOPBACK,UP&amp;gt; mtu 16436 qdisc noqueue &lt;br /&gt;
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00&lt;br /&gt;
    inet 127.0.0.1/8 brd 127.255.255.255 scope host lo&lt;br /&gt;
4: bond0: &amp;lt;BROADCAST,MULTICAST,MASTER,UP&amp;gt; mtu 1500 qdisc noqueue &lt;br /&gt;
    link/ether 00:0c:29:73:26:19 brd ff:ff:ff:ff:ff:ff&lt;br /&gt;
    inet 10.17.3.25/16 brd 10.17.255.255 scope global bond0&lt;br /&gt;
6: eth0: &amp;lt;BROADCAST,MULTICAST,SLAVE,UP&amp;gt; mtu 1500 qdisc pfifo_fast master bond0 qlen 1000&lt;br /&gt;
    link/ether 00:0c:29:73:26:19 brd ff:ff:ff:ff:ff:ff&lt;br /&gt;
8: eth1: &amp;lt;BROADCAST,MULTICAST,SLAVE,UP&amp;gt; mtu 1500 qdisc pfifo_fast master bond0 qlen 1000&lt;br /&gt;
    link/ether 00:0c:29:73:26:19 brd ff:ff:ff:ff:ff:ff&lt;br /&gt;
1: venet0: &amp;lt;BROADCAST,POINTOPOINT,NOARP,UP&amp;gt; mtu 1500 qdisc noqueue &lt;br /&gt;
    link/void&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
Route:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ip r&lt;br /&gt;
&lt;br /&gt;
10.17.0.0/16 dev bond0  proto kernel  scope link  src 10.17.3.25 &lt;br /&gt;
169.254.0.0/16 dev bond0  scope link &lt;br /&gt;
default via 10.17.0.1 dev bond0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==  Traffic shaping ==&lt;br /&gt;
=== Virtuozzo traffic shaping tools ===&lt;br /&gt;
Just replace old netdev to new bonding device (bond0)  &lt;br /&gt;
&lt;br /&gt;
vi /etc/sysconfig/vz&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Network traffic parameters&lt;br /&gt;
TRAFFIC_SHAPING=yes&lt;br /&gt;
BANDWIDTH=&amp;quot;bond0:102400&amp;quot;&lt;br /&gt;
TOTALRATE=&amp;quot;bond0:1:4096&amp;quot;&lt;br /&gt;
RATE=&amp;quot;bond0:1:8&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and do the rest as usuall&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# vzctl set $veid --ratebound $bound --rate $rif:$class:$rate --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Traffic shaping with tc ===&lt;br /&gt;
Where is no specifics here, see [[Traffic shaping with tc]].&lt;br /&gt;
&lt;br /&gt;
As a result in: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ip a s  bond0&lt;br /&gt;
4: bond0: &amp;lt;BROADCAST,MULTICAST,MASTER,UP&amp;gt; mtu 1500 qdisc cbq &lt;br /&gt;
##NOTE:Class Based Queueing tc was added          ^^^^^^^^^^  &lt;br /&gt;
    link/ether 00:0c:29:07:d4:c3 brd ff:ff:ff:ff:ff:ff&lt;br /&gt;
    inet 10.17.3.41/16 brd 10.17.255.255 scope global bond0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>Bwian</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Bonding&amp;diff=3422</id>
		<title>Bonding</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Bonding&amp;diff=3422"/>
		<updated>2007-09-04T06:42:28Z</updated>

		<summary type="html">&lt;p&gt;Bwian: /* Load bond driver/module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Linux allows binding multiple network interfaces into a single channel/NIC.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The Linux bonding driver provides a method for aggregating&lt;br /&gt;
multiple network interfaces into a single logical &amp;quot;bonded&amp;quot; interface.&lt;br /&gt;
The behavior of the bonded interfaces depends upon the mode; generally&lt;br /&gt;
speaking, modes provide either hot standby or load balancing services.&lt;br /&gt;
Additionally, link integrity monitoring may be performed.&lt;br /&gt;
&lt;br /&gt;
== Setting up bounding on a RHEL/CentOS 4 system ==&lt;br /&gt;
&lt;br /&gt;
===Create a bond0 configuration file===&lt;br /&gt;
&lt;br /&gt;
Red Hat Linux stores network configuration in /etc/sysconfig/network-scripts/ directory. First, you need to create bond0 config file:&lt;br /&gt;
&lt;br /&gt;
 # vi /etc/sysconfig/network-scripts/ifcfg-bond0&lt;br /&gt;
&lt;br /&gt;
Append following lines to it:&lt;br /&gt;
&lt;br /&gt;
====In case of static IP====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=bond0&lt;br /&gt;
IPADDR=x.x.x.x&lt;br /&gt;
NETWORK=y.y.y.y&lt;br /&gt;
NETMASK=z.z.z.z&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
x.x.x.x is an IP address of HW.   &lt;br /&gt;
&lt;br /&gt;
y.y.y.y is an Network address of HW.  &lt;br /&gt;
&lt;br /&gt;
z.z.z.z is an net mask address of HW (usually 255.255.255.0).&lt;br /&gt;
&lt;br /&gt;
Replace above IP data with your actual IP address. Save file and exit to shell prompt.&lt;br /&gt;
&lt;br /&gt;
====In case of DHCP====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=bond0&lt;br /&gt;
BOOTPROTO=dhcp&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Modify eth0 and eth1 config files===&lt;br /&gt;
&lt;br /&gt;
Open both configuration using vi text editor and make sure file read as follows for eth0 interface&lt;br /&gt;
&lt;br /&gt;
 # vi /etc/sysconfig/network-scripts/ifcfg-eth0&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth0&lt;br /&gt;
USERCTL=no&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open eth1 configuration file using vi text editor:&lt;br /&gt;
&lt;br /&gt;
 vi /etc/sysconfig/network-scripts/ifcfg-eth1&lt;br /&gt;
&lt;br /&gt;
Make sure file read as follows for eth1 interface:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
DEVICE=eth1&lt;br /&gt;
USERCTL=no&lt;br /&gt;
ONBOOT=yes&lt;br /&gt;
MASTER=bond0&lt;br /&gt;
SLAVE=yes&lt;br /&gt;
BOOTPROTO=none&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Save file and exit to shell prompt.&lt;br /&gt;
&lt;br /&gt;
=== Load bond driver/module ===&lt;br /&gt;
Make sure the bonding module is loaded when the channel-bonding interface (bond0) is brought up. You need to modify the kernel modules configuration file:&lt;br /&gt;
&lt;br /&gt;
 # vi /etc/modprobe.conf&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
alias bond0 bonding&lt;br /&gt;
options bond0 miimon=100&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
You can learn more about all bonding options in the kernel source documentation file  &amp;quot;Documentation/networking/bonding.txt&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Test the configuration ===&lt;br /&gt;
First, load the bonding module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# modprobe bonding&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Restart networking service in order to up bond0 interface:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# service network restart&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Check proc info:&lt;br /&gt;
&lt;br /&gt;
 # cat /proc/net/bonding/bond0 &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Ethernet Channel Bonding Driver: v2.6.3 (June 8, 2005)&lt;br /&gt;
&lt;br /&gt;
Bonding Mode: load balancing (round-robin)&lt;br /&gt;
MII Status: up&lt;br /&gt;
MII Polling Interval (ms): 0&lt;br /&gt;
Up Delay (ms): 0&lt;br /&gt;
Down Delay (ms): 0&lt;br /&gt;
&lt;br /&gt;
Slave Interface: eth0&lt;br /&gt;
MII Status: up&lt;br /&gt;
Link Failure Count: 0&lt;br /&gt;
Permanent HW addr: 00:0c:29:07:d4:c3&lt;br /&gt;
&lt;br /&gt;
Slave Interface: eth1&lt;br /&gt;
MII Status: up&lt;br /&gt;
Link Failure Count: 0&lt;br /&gt;
Permanent HW addr: 00:0c:29:07:d4:cd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
List all interfaces: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#ip a&lt;br /&gt;
&lt;br /&gt;
2: lo: &amp;lt;LOOPBACK,UP&amp;gt; mtu 16436 qdisc noqueue &lt;br /&gt;
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00&lt;br /&gt;
    inet 127.0.0.1/8 brd 127.255.255.255 scope host lo&lt;br /&gt;
4: bond0: &amp;lt;BROADCAST,MULTICAST,MASTER,UP&amp;gt; mtu 1500 qdisc noqueue &lt;br /&gt;
    link/ether 00:0c:29:73:26:19 brd ff:ff:ff:ff:ff:ff&lt;br /&gt;
    inet 10.17.3.25/16 brd 10.17.255.255 scope global bond0&lt;br /&gt;
6: eth0: &amp;lt;BROADCAST,MULTICAST,SLAVE,UP&amp;gt; mtu 1500 qdisc pfifo_fast master bond0 qlen 1000&lt;br /&gt;
    link/ether 00:0c:29:73:26:19 brd ff:ff:ff:ff:ff:ff&lt;br /&gt;
8: eth1: &amp;lt;BROADCAST,MULTICAST,SLAVE,UP&amp;gt; mtu 1500 qdisc pfifo_fast master bond0 qlen 1000&lt;br /&gt;
    link/ether 00:0c:29:73:26:19 brd ff:ff:ff:ff:ff:ff&lt;br /&gt;
1: venet0: &amp;lt;BROADCAST,POINTOPOINT,NOARP,UP&amp;gt; mtu 1500 qdisc noqueue &lt;br /&gt;
    link/void&lt;br /&gt;
&amp;lt;/pre&amp;gt; &lt;br /&gt;
Route:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ip r&lt;br /&gt;
&lt;br /&gt;
10.17.0.0/16 dev bond0  proto kernel  scope link  src 10.17.3.25 &lt;br /&gt;
169.254.0.0/16 dev bond0  scope link &lt;br /&gt;
default via 10.17.0.1 dev bond0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==  Traffic shaping ==&lt;br /&gt;
=== Virtuozzo traffic shaping tools ===&lt;br /&gt;
Just replace old netdev to new bonding device (bond0)  &lt;br /&gt;
&lt;br /&gt;
vi /etc/sysconfig/vz&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## Network traffic parameters&lt;br /&gt;
TRAFFIC_SHAPING=yes&lt;br /&gt;
BANDWIDTH=&amp;quot;bond0:102400&amp;quot;&lt;br /&gt;
TOTALRATE=&amp;quot;bond0:1:4096&amp;quot;&lt;br /&gt;
RATE=&amp;quot;bond0:1:8&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
and do the rest as usuall&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# vzctl set $veid --ratebound $bound --rate $rif:$class:$rate --save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Traffic shaping with tc ===&lt;br /&gt;
Where is no specifics here, see [[Traffic shaping with tc]].&lt;br /&gt;
&lt;br /&gt;
As a result in: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# ip a s  bond0&lt;br /&gt;
4: bond0: &amp;lt;BROADCAST,MULTICAST,MASTER,UP&amp;gt; mtu 1500 qdisc cbq &lt;br /&gt;
##NOTE:Class Based Queueing tc was added          ^^^^^^^^^^  &lt;br /&gt;
    link/ether 00:0c:29:07:d4:c3 brd ff:ff:ff:ff:ff:ff&lt;br /&gt;
    inet 10.17.3.41/16 brd 10.17.255.255 scope global bond0&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>Bwian</name></author>
		
	</entry>
</feed>