Configuring Ubuntu 12.04 in OpenVZ on CentOS 6.4

This howto is based on two sources: Official wiki and Amutu blog entry. In short, the main difficulty is in bridge network configuration: correct network configuration doesn’t work in CentOS 6.4 while NetworkManager is running. I compiled official documentation and fix found in Amutu blog here in one entry.

I assume you have clean installed CentOS. I tried all on x32 hardware, so you may need to fix container type in container creation section if you use x64 CentOS. All commands below need to be issued as root.

Installation of OpenVZ

wget -O /etc/yum.repos.d/openvz.repo http://download.openvz.org/openvz.repo
rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ
yum install vzkernel vzctl vzquota

Add next two lines at the end of sysctl.conf:

# vim /etc/sysctl.conf
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.conf.default.forwarding=1

Create bridge device (edit file ifcfg-vmbr0):

# vim /etc/sysconfig/network-scripts/ifcfg-vmbr0
DEVICE="vmbr0"
BOOTPROTO="static"
IPV6INIT="no"
ONBOOT="yes"
TYPE="Bridge"
DELAY=0
IPADDR=[your host ip]
NETMASK=255.255.255.0
GATEWAY=[your gateway]

Connect bridge to ethernet device (in my case it is eth0, so edit ifcfg-eth0):

# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
ONBOOT="yes"
IPV6INIT="no"
TYPE="Ethernet"
BRIDGE="vmbr0"

Allowing automated configuration of bridge for containers in vznet.conf:

# vim /etc/vz/vznet.conf
#!/bin/bash
EXTERNAL_SCRIPT="/usr/sbin/vznetaddbr"

Fixing NetworkManager issue

chkconfig NetworkManager off
chkconfig --levels 35 network on
service NetworkManager stop
service network restart

Reboot OpenVZ host system.

Creation of container with bridged connection

All commands below need to be issued as root. Create a container:

vzctl create 101 --ostemplate ubuntu-12.04-x86 --config vswap-1g

Configure the container, type in terminal:

vzctl set 101 --save --name container101
vzctl set 101 --save --onboot yes
vzctl set 101 --save --hostname container101.domain.com
vzctl set 101 --save --netif_add eth0,,,FE:FF:FF:FF:FF:FF
vzctl set 101 --save --searchdomain domain.com
vzctl set 101 --save --nameserver 8.8.8.8 --nameserver 8.8.4.4
vzctl set 101 --save --cpus 1
vzctl set 101 --save --ram 1G
vzctl set 101 --save --swap 512M
vzctl set 101 --save --diskspace 10G
vzctl start 101
vzctl exec 101 passwd

Official wiki recommends to use big MAC.

To configure network in container, edit interfaces:

# vim /vz/root/101/etc/network/interfaces
auto lo eth0
iface lo inet loopback
iface eth0 inet static
	address [your container ip]
	netmask 255.255.255.0
	gateway [your gateway]

Enter container and reboot it:

vzctl enter 101
reboot