Open main menu

OpenVZ Virtuozzo Containers Wiki β

Changes

VEs and HNs in same subnets

854 bytes added, 13:20, 26 November 2013
Added GATEWAY to ifcfg-eth0 example.
This describes a method of setting up networking for a host and its VEs such that the networking configuration for the VEs can be configured exactly as if the VEs were standalone hosts of their own in the same subnets or VLAN as the host. This method makes use of the Virtual Ethernet device and bridges between the host and its containers. This technique has the advantage of allowing IPv6 network configurations to work on both VEs and hosts as they normally would. In particular, both hosts and VEs can use IPv6 autoconfiguration. The network configuration of a VE can be identical to that of a non-VE system.
In the following example the host has two physical interfaces and we are setting up the network configuration for VE 100. The host IP configuration is moved out of the ethN interface configs and into the vzbrN brN interface config scripts (ifcfg-vzbr0 br0 and ifcfg-vzbr1br1). Ie. the host IP configuration will now reside on the vzbrN brN interfaces instead of the ethN interfaces. The example also assumes IPv4 is configured statically, whereas IPv6 is auto-configured.
==Configure host bridge interfaces==
 
Steps 1 through 4 are done only once on the host.
 
1. (Optional) Verify that you can create a bridge interfaces for each physical interface on the host.
/usr/sbin/brctl addbr vzbr0br0 /usr/sbin/brctl addbr vzbr1br1
If the above commands do not work you may need to install the bridge-utils package.
2. Make note of the existing IP configuration in the hosts ifcfg-ethN files. Also, record the hardware MAC addresses of the ethernet interfaces from the output of 'ifconfig'.  /sbin/ifconfig eth0 /sbin/ifconfig eth1  Then, modify the ifcfg-ethN files on the host so that they ONLY bridge to the corresponding vzbrN brN interface. /etc/sysconfig/network-scripts/ifcfg-eth0 should look like:
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
BRIDGE=vzbr0br0
Similarly ifcfg-eth1 will look like:
BOOTPROTO=none
ONBOOT=yes
BRIDGE=vzbr1br1
Note that the ifcfg-ethN files on the host do not contain any IP information anymore.
3. Create ifcfg-vzbrN brN files and copy the IP configuration that was previously in the ifcfg-ethN files into ifcfg-vzbrNbrN. Here's what host:/etc/sysconfig/network-scripts/ifcfg-vzbr0 br0 would look like assuming the IPv4 address is assigned statically and IPv6 auto-configuration (SLAAC) is used:
DEVICE=vzbr0br0
BOOTPROTO=static
IPADDR=xxx.xxx.xxx.xxx
NETMASK=aaa.aaa.aaa.aaa
ONBOOT=yes
TYPE=bridgeBridge MACADDR=mm:mm:mm:mm:mm:mm
Similarly, ifcfg-vzbr1 br1 should look like:
DEVICE=vzbr1br1
BOOTPROTO=static
IPADDR=yyy.yyy.yyy.yyy
NETMASK=bbb.bbb.bbb.bbb
ONBOOT=yes
TYPE=Bridge MACADDR=nn:nn:nn:nn:nn:nn Note that TYPE 'Bridge' is case-sensitive. Otherwise, the bridgeinterfaces will not initialize correctly during boot. The bridge MACADDR should be hard-coded to match the corresponding hardware MAC address of the ethernet interface. Otherwise the default behaviour is to use the lowest MAC address of all the interfaces in the bridge. This is to prevent the bridge MAC and any auto-configured IPv6 address on the bridge interface from changing as VEs are created, started, or stopped.
4. On the host, do a 'service network restart' and verify the host has both IPv4 and IPv6 connectivity to its vzbrN brN interfaces.
==Create the VE veth interfaces==
5. Create the VE as you normally would , except do NOT specify any IP address, just the hostname. Specifying an IP address during VE creation creates an unwanted venet interface which is not used in this configuration.
/usr/sbin/vzctl create 100 --ostemplate name --hostname name
==Bridge the host and VE==
7. Next we add the host vethN interfaces to the host bridged interfaces (vzbrNbrN).
Create host:/etc/sysconfig/network-scripts/ifcfg-veth100.0
DEVICE=veth100.0
ONBOOT=no
BRIDGE=vzbr0br0
Create host:/etc/sysconfig/network-scripts/ifcfg-veth100.1
DEVICE=veth100.1
ONBOOT=no
BRIDGE=vzbr1br1
To make the above take effect, either start the VE,
Or if it's already started then manually add each VE interface to its corresponding bridge using:
/usr/sbin/brctl addif vzbr0 br0 veth100.0 /usr/sbin/brctl addif vzbr1 br1 veth100.1
8. Verify each bridge includes the host interface and the veth interfaces for each VE:
NETMASK=yyy.yyy.yyy.yyy
ONBOOT=yes
GATEWAY=zzz.zzz.zzz.zzz
10. Initialize the interfaces and restart the network service on the container.
and you will be good to go. The CT will now autoconfigure the network interfaces the next time it sees an RA.
NOTE: Due to bug [http://bugzilla.openvz.org/show_bug.cgi?id=1723 1723] this setup might not work: Enabling the routing on CT0 can effectively kill all IPv6 connectivity for the CT, depending on the setup.(This bug is reported to be solved since 2011-06-07, so this shouldn't be an issue anymore.)
==See also==
14
edits