OpenVZ - Create a Container with VETH Interface

This howto shows how to create an OpenVZ container with VETH interface.

Create the container

vzctl create 10221 --ostemplate centos-6-x86_64 --config vswap-1g

Configure the container

vzctl set 10221 --save --name server10221
vzctl set 10221 --save --onboot yes
vzctl set 10221 --save --hostname server10221.example.com
vzctl set 10221 --save --netif_add eth0,,,FE:FF:FF:FF:FF:FF
vzctl set 10221 --save --searchdomain example.com
vzctl set 10221 --save --nameserver 8.8.8.8 --nameserver 8.8.4.4
vzctl set 10221 --save --cpus 4
vzctl set 10221 --save --ram 8G
vzctl set 10221 --save --swap 4G
vzctl set 10221 --save --diskspace 100G
vzctl start 10221
vzctl exec 10221 passwd

Configure the network on RHEL (CentOS) based containers

cat << _EOF_ > /vz/root/10221/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
HOSTNAME="server10221"
IPV6INIT="no"
MTU="1500"
TYPE="Ethernet"
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.10.221
NETMASK=255.255.255.0
GATEWAY=192.168.10.1
_EOF_

vzctl exec $CTID /etc/init.d/network restart

Configure the network in Debian-based containers

cat << _EOF_ > /vz/root/10221/etc/network/interfaces
auto lo eth0
iface lo inet loopback
iface eth0 inet static
        address 192.168.10.221
        netmask 255.255.255.0
        gateway 192.168.10.1
_EOF_

vzctl exec $CTID /etc/init.d/networking restart

Done

social