Difference between revisions of "Adding ethernet interface to openVZ container"

From Notes_Wiki
m
Line 2: Line 2:
=Adding ethernet interface (eth0, eth1, etc.) to container=
=Adding ethernet interface (eth0, eth1, etc.) to container=


To add ethernet interface to container use command:
==Enable auto adding of interface to bridge on container start==
Enable automated addition of create interface to bridge using:
<pre>
<pre>
vzctl set <CID> --netif_add <ifname> --save
echo 'EXTERNAL_SCRIPT="/usr/sbin/vznetaddbr"' >> /etc/vz/vznet.conf
</pre>
</pre>
where <ifname> can be eth0, eth1 etc.  
which basically adds '<tt>EXTERNAL_SCRIPT="/usr/sbin/vznetaddbr"</tt>' to /etc/vz/vznet.conf


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:
==Add ethernet interface to bridge==
To add ethernet interface to a container use command:
<pre>
<pre>
service network start
vzctl set <CID> --netif_add <ifname>,,,,<bridge-name> --save
</pre>
</pre>
 
where <ifname> can be eth0, eth1 etc. and <bridge-name> is the name of bridge on base machine where interface should be added.  The three omitted parameters are mac_address in container, device name on base machine and mac address on base machine respectively.  If these parameters are omitted as shown above then the get reasonable defaults.
To configure static IPs for container using interface, say eth0, use following configuration as '<tt>/etc/sysconfig/network-scripts/ifcfg-eth0</tt>'
To configure static IPs for container using interface, say eth0, use following configuration as '<tt>/etc/sysconfig/network-scripts/ifcfg-eth0</tt>'
<pre>
<pre>

Revision as of 12:51, 15 March 2014

<yambe:breadcrumb>OpenvZ</yambe:breadcrumb>

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

Enable auto adding of interface to bridge on container start

Enable automated addition of create interface to bridge using:

echo 'EXTERNAL_SCRIPT="/usr/sbin/vznetaddbr"' >> /etc/vz/vznet.conf

which basically adds 'EXTERNAL_SCRIPT="/usr/sbin/vznetaddbr"' to /etc/vz/vznet.conf


Add ethernet interface to bridge

To add ethernet interface to a container use command:

vzctl set <CID> --netif_add <ifname>,,,,<bridge-name> --save

where <ifname> can be eth0, eth1 etc. and <bridge-name> is the name of bridge on base machine where interface should be added. The three omitted parameters are mac_address in container, device name on base machine and mac address on base machine respectively. If these parameters are omitted as shown above then the get reasonable defaults.

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