Previous page

Next page

Locate page in Contents

Print this page

Connecting Containers to Virtual Networks

With the implementation of veth virtual adapters allowing Containers to function as full participants on the network, it has become possible to include Containers in a wide range of network configurations the most common of which are Ethernet networks and VLANs (virtual local area networks). The process of connecting veth virtual network adapters to an Ethernet network or to a VLAN is carried out using certain physical and VLAN adapters, respectively, available on the server and involves completing the following tasks:

  1. Creating a Virtual Network that will act as an intermediary between the veth adapters and the physical/VLAN adapter.
  2. Connecting the veth virtual adapters you want to include in an Ethernet network/VLAN to the Virtual Network.
  3. Joining the Virtual Network where the veth virtual adapters are included to the corresponding physical/VLAN adapter.

After completing these tasks, the Container virtual network adapters will be able to communicate with any computer on the network (either Ethernet or VLAN) where they are included and have no direct access to the computers joined to other networks.

The process of creating new Virtual Networks and joining physical and VLAN adapters to these Virtual Network is described in the Creating a Virtual Network and Connecting an Adapter to a Virtual Network subsections, respectively. So, in the example below we assume the following:

  • The eth0 physical adapter and the vznetwork1 Virtual Network exist on the server.
  • The eth0 physical adapter is connected to the local Ethernet network and to the vznetwork1 Virtual Network.
  • You want to connect Container 101 and Container 102 to the local Ethernet network.

To join Container 101 and 102 to the local Ethernet network behind the eth0 adapter, you should connect these Containers to the vznetwork1 Virtual Network. This can be done as follows:

  1. Find out the name of the veth Ethernet interfaces inside Container 101 and 102:

    # vzlist -a -o ctid,ifname

    CTID IFNAME

    101 eth1

    102 eth0

    103 -

    The command output shows that the veth Ethernet interfaces inside Container 101 and 102 have the names of eth1 and eth0 , respectively.

    Note: To add a veth adapter to a Virtual Network, you must use the name of its Ethernet interface inside the Container.

  2. Join the veth adapters to the vznetwork1 Virtual Network:
    • Add the veth adapter of Container 101 to the Virtual Network:

      # pctl set 101 --ifname eth1 --network vznetwork1 --save

      Saved parameters for Container 101

    • Add the veth adapter of Container 102 to the Virtual Network:

      # pctl set 102 --ifname eth0 --network vznetwork1 --save

      Saved parameters for Container 102

After completing these tasks, Container 101 and Container 102 will be able to access any of the servers in the network where the eth0 physical adapter is connected.

At any time, you can disconnect the veth virtual network adapters of Container 101 and 102 from the vznetwork1 Virtual Network by executing the following commands:

  • To disconnect the veth adapter of Container 101 from the Virtual Network:

    # pctl set 101 --ifname eth1 --network "" --save

    Saved parameters for Container 101

  • To disconnect the veth adapter of Container 102 from the Virtual Network:

    # pctl set 102 --ifname eth1 --network "" --save

    Saved parameters for Container 102