Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

Using private IPs for Hardware Nodes

4,307 bytes added, 10:33, 24 July 2007
<u>Making the configuration persistent</u> (TODO)
[[Image:PrivateIPs_fig2.gif|The resulted OVZ Node configuration]]
=== <u>Making the configuration persistent</u> (TODO) ===A Hardware Node configuration ==== Set up a bridge on a HN ====This can be done with help of ordinary initscripts configuration i suppose,by configuring <code>ifcfg-*</code> files located in <code>/etc/sysconfig/network-scripts/<br/code>. while VEs Assuming you had a configuration will require creating additional script based on [[Virtual_Ethernet_device#Making_a_vethfile (e.g. <code>ifcfg-device_persistent|Making a veth-device persistent]] schemeeth0</code>) like:<pre>DEVICE=eth0ONBOOT=yesIPADDR=10.0.0.2NETMASK=255.255.255.0GATEWAY=10.0.0.1</pre>
<br>
To make bridge <code>br0</code> automatically created you can create <code>ifcfg-br0</code>:
<pre>
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
IPADDR=10.0.0.2
NETMASK=255.255.255.0
GATEWAY=10.0.0.1
</pre>
 
and edit <code>ifcfg-eth0</code> file to add <code>eth0</code> interface into the bridge <code>br0</code>:
<pre>
DEVICE=eth0
ONBOOT=yes
BRIDGE=br0
</pre>
 
==== Edit the VE's configuration ====
Add some parameters to the <code>/etc/vz/conf/$VEID.conf</code> which will be used during the network configuration:
* Add/change CONFIG_CUSTOMIZED="yes" (indicates that a custom script should be run on a VE start)
* Add VETH_IP_ADDRESS="<VE IP>/<MASK>" (a VE can have multiple IPs separated by spaces)
* Add VE_DEFAULT_GATEWAY="<VE DEFAULT GATEWAY>"
* Add BRIDGEDEV="<BRIDGE NAME>" (a bridge name to which the VE veth interface should be added)
 
An example:
<pre>
# Network customization section
CONFIG_CUSTOMIZED="yes"
VETH_IP_ADDRESS="85.86.87.195/26"
VE_DEFAULT_GATEWAY="85.86.87.193"
BRIDGEDEV="br0"
</pre>
 
==== Create a custom network configuration script ====
which should be called each time a VE started (e.g. <code>/usr/sbin/vznetcfg.custom</code>):
<pre>
#!/bin/bash
# /usr/sbin/vznetcfg.custom
# a script to bring up bridged network interfaces (veth's) in a VE
 
GLOBALCONFIGFILE=/etc/vz/vz.conf
VECONFIGFILE=/etc/vz/conf/$VEID.conf
vzctl=/usr/sbin/vzctl
ip=/sbin/ip
. $GLOBALCONFIGFILE
. $VECONFIGFILE
 
NETIF_OPTIONS=`echo $NETIF | sed 's/,/\n/g'`
for str in $NETIF_OPTIONS; do \
# getting 'ifname' parameter value
if [[ "$str" =~ "^ifname=" ]]; then
# remove the parameter name from the string (along with '=')
VEIFNAME=${str#*=};
fi
# getting 'host_ifname' parameter value
if [[ "$str" =~ "^host_ifname=" ]]; then
# remove the parameter name from the string (along with '=')
VZHOSTIF=${str#*=};
fi
done
 
if [ ! -n "$VETH_IP_ADDRESS" ]; then
echo "According to $CONFIGFILE VE$VEID has no veth IPs configured."
exit 1
fi
 
if [ ! -n "$VZHOSTIF" ]; then
echo "According to $CONFIGFILE VE$VEID has no veth interface configured."
exit 1
fi
 
if [ ! -n "$VEIFNAME" ]; then
echo "Corrupted $CONFIGFILE: no 'ifname' defined for host_ifname $VZHOSTIF."
exit 1
fi
 
for IP in $VETH_IP_ADDRESS; do
echo "Initializing interface $VZHOSTIF for VE$VEID."
/sbin/ifconfig $VZHOSTIF 0
done
 
VEROUTEDEV=$VZHOSTIF
 
if [ -n "$BRIDGEDEV" ]; then
echo "Adding interface $VZHOSTIF to the bridge $BRIDGEDEV."
VEROUTEDEV=$BRIDGEDEV
/usr/sbin/brctl addif $BRIDGEDEV $VZHOSTIF
fi
 
# Up the interface $VEIFNAME link in VE$VEID
$vzctl exec $VEID $ip link set $VEIFNAME up
 
for IP in $VETH_IP_ADDRESS; do
echo "Adding an IP $IP to the $VEIFNAME for VE$VEID."
$vzctl exec $VEID $ip address add $IP dev $VEIFNAME
 
# removing the netmask
IP_STRIP=${IP%%/*};
 
echo "Adding a route from VE0 to VE$VEID."
$ip route add $IP_STRIP dev $VEROUTEDEV
done
 
if [ -n "$VE0_IP" ]; then
echo "Adding a route from VE$VEID to VE0."
$vzctl exec $VEID $ip route add $VE0_IP dev $VEIFNAME
fi
 
if [ -n "$VE_DEFAULT_GATEWAY" ]; then
echo "Setting $VE_DEFAULT_GATEWAY as a default gateway for VE$VEID."
$vzctl exec $VEID \
$ip route add default via $VE_DEFAULT_GATEWAY dev $VEIFNAME
fi
 
exit 0
</pre>
 
==== Make the script to be run on a VE start ====
In order to run above script on a VE start create the following <code>/etc/vz/vznet.conf</code> file:
<pre>
#!/bin/bash
EXTERNAL_SCRIPT="/usr/sbin/vznetcfg.custom"
</pre>
{{Note|both <code>/etc/vz/vznet.conf</code> and <code>/usr/sbin/vznetcfg.custom</code> should be executable files.}}
 
==== Setting the route VE -> HN ====
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:
# Add an entry VE0_IP="VE0 IP" to the <code>$VEID.conf</code>
# Add an entry VE0_IP="VE0 IP" to the <code>/etc/vz/vz.conf</code> (the global configuration config file)
# Implement some smart algorithm to determine the VE0 IP right in the custom network configuration script
All the variants have their pros and cons, nevertheless for HN static IP configuration variant 2 seems acceptable (and the most simple).
== (2) An OVZ Hardware Node has two ethernet interfaces (TODO) ==