Adding ethernet interface to openVZ container

From Notes_Wiki
Revision as of 14:37, 9 January 2013 by Saurabh (talk | contribs)

Adding ethernet interface (eth0, eth1, etc.) to container

To add ethernet interface to container use command:

vzctl set <CID> --netif_add <ifname> --save

where <ifname> can be eth0, eth1 etc.

When the interface is added to container a corresponding interface with name such as veth<CID>.<n> where n is 0 for eth0, 1 for eth1, etc. is automatically added in base host. In base host this veth* interface should then be added to a bridge so that packets sent to eth0, eth1 etc. in container can be forwarded via veth*.0 or veth*.1 through bridges to desired destinations. To create bridge in the base machine use steps mentioned at Creating bride interfaces (br0) for virtual hosts to use shared interface

When interfaces are added in this manner, the corresponding interface configuration file should be created and network service should be enabled on start-up. To enable network service on start-up use:

service network start

To configure static IPs for container using interface, say eth0, use following configuration as '/etc/sysconfig/network-scripts/ifcfg-eth0'

DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=<IP address>
NETMASK=<Netmask>
GATEWAY=<Default Gateway>
DNS1=<Local recursive DNS IP>
NM_CONTROLLED=no