6,534
edits
Changes
use template:legacy
{{Legacy}} This article describes how to assign public IPs to VEs containers running on OVZ Hardware Nodes in case you have a following network topology:
[[Image:PrivateIPs_fig1.gif|An initial network topology]]
== Using a spare IP in the same range ==
If you have a spare IP to use, you could assign this as a subinterface and use this as nameserver:
<pre>[HN] ifconfig eth0:1 *.*.*.*
[HN] vzctl set 101 --nameserver *.*.*.*</pre>
== Prerequisites ==
This configuration was tested on a RHEL5 OpenVZ Hardware Node and a container based on a Fedora Core 5 template.Other host OSs and templates might require some configuration changes, please add corresponding OS specific changes if you've faced any. 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. This article assumes you have already [[Quick installation|installed OpenVZ]], prepared the [[OS template cache]](s) and have [[Basic_operations_in_OpenVZ_environment|VEcontainer(s) created]]. If not, follow the links to perform the steps needed.{{Note|don't assign an IP after VE container creation.}}<br>== (1) An OVZ Hardware Node has the only one ethernet Ethernet interface ==
(assume eth0)
=== <u>Hardware Node configuration</u> === {{Warning|if you are '''configuring''' the node '''remotely''' you '''must''' prepare a '''script''' with the below commands and run it in background with the redirected output or you'll '''lose the access''' to the Node.}}
==== Create a bridge device ====
==== Remove an IP from eth0 interface ====
==== Add eth0 interface into the bridge ====
==== Assign the IP to the bridge ====
(the same that was assigned on eth0 earlier)
==== Resurrect the default routing ====
==== A script example ====
</pre>
===Container configuration = Start a VE ====<pre>[HN]# vzctl start 101</pre>
==== Add Start a [[Virtual_Ethernet_device|veth interface]] to the VE container ====<pre> [HN]# vzctl set start 101 --netif_add eth0 –save</pre>
==== Add a [[Virtual_Ethernet_device|veth interface]] to the container ==== [HN]# vzctl set 101 --netif_add eth0 --save ==== Set up an IP to the newly created VEcontainer's veth interface ====<pre> [HN]# vzctl exec 101 ifconfig eth0 85.86.87.194195/26</pre>
==== Add the container's veth interface to the bridge ==== [HN]# brctl addif br0 veth101.0 {{Note|There will be a delay of about 15 seconds(default for 2.6.18 kernel) while the bridge software runs STP to detect loops and transitions the veth interface to the forwarding state.<!-- /sys/class/net/$BR_NAME/bridge/forward_delay in SEC*USER_HZ -->}} ==== Set up the default route for the VE container ====<pre> [HN]# vzctl exec 101 ip route change add default via 85.86.87.192 193 dev eth0</pre>
==== (Optional) Add the VE's veth interface to the bridge CT↔HN routes ====<pre>The above configuration provides the following connections:* CT X ↔ CT Y (where CT X and CT Y can locate on any OVZ HN)* CT ↔ Internet Note that * The accessability of the CT from the HN depends on the local gateway providing NAT (probably - yes) * The accessability of the HN from the CT depends on the ISP gateway being aware of the local network (probably not) So to provide CT ↔ HN accessibility despite the gateways' configuration you can add the following routes: [HN]# brctl addif ip route add 85.86.87.195 dev br0 veth101 [HN]# vzctl exec 101 ip route add 10.0</pre>.0.2 dev eth0 === Resulting OpenVZ Node configuration ===[[Image:PrivateIPs_fig2.gif|Resulting OpenVZ Node configuration]]
=== Making the configuration persistent === ==== (Optional) Make Set up a bridge on a HN(s) to be accessible from a VE ====The This can be done by configuring the <code>ifcfg-*</code> files located in <code>/etc/sysconfig/network-scripts/</code>. Assuming you had a configuration above provides following connections availablefile (e.g. <code>ifcfg-eth0</code>) like:
<pre>
</pre>
== (2) An OVZ Hardware Node has two ethernet interfaces (TODO) Putting containers to different subnetworks ==(assume eth0 It's enough to set up the correct $VETH_IP_ADDRESS and eth1)$VE_DEFAULT_GATEWAY values in the [[Using_private_IPs_for_Hardware_Nodes#Edit_the_container.27s_configuration|above configuration]].
== See also ==
* [[Virtual network device]]
* [[Differences between venet and veth]]
[[Category: HOWTO]]
[[Category: Networking]]