0

I have two OpenVZ Hosts with containers on them. This is the current layout:

Host-A: (eth0 (connected to internet), eth1 (connected to Host-B))

Host-B: (eth0 (connected to internet), eth1 (connected to Host-A))

Host-A and Host-B have OpenVZ containers on them. Host-A and Host-B have one public IPv4 address (each), the containers do not have public IPs, they need to be on an internal private network.

How do I configure the network so containers on both hosts can communicate to one another and access the internet.

1

After getting an overwhelming number of responses on SF... not!?!, I did my own research the figured it out. This is how I did it.

Configuration

-SSH to Host A and update /etc/network/interfaces as below:

auto lo
iface lo inet loopback

iface eth1 inet manual

auto vmbr1
iface vmbr1 inet static
        address 10.0.2.99
        netmask 255.255.255.0
        bridge_ports eth1
        bridge_stp off
        bridge_fd 0

auto eth0
iface eth0 inet static
        address public_ip_here
        netmask 255.255.255.0
        gateway public_ip_gateway_here

auto vmbr0
iface vmbr0 inet static
        address 10.0.1.1
        netmask 255.255.255.0
        bridge_ports none
        bridge_stp off
        bridge_fd 0

        post-up echo 1 > /proc/sys/net/ipv4/ip_forward
        post-up   iptables -t nat -A POSTROUTING -s '10.0.1.0/24' -o eth0 -j MASQUERADE
        post-down iptables -t nat -D POSTROUTING -s '10.0.1.0/24' -o eth0 -j MASQUERADE

-SSH to Host B and updated /etc/network/interfaces as below:

auto lo
iface lo inet loopback

iface eth1 inet manual

auto vmbr1
iface vmbr1 inet static
        address 10.0.2.199
        netmask 255.255.255.0
        bridge_ports eth1
        bridge_stp off
        bridge_fd 0

auto eth0
iface eth0 inet static
        address public_ip_here
        netmask 255.255.255.0
        gateway public_ip_gateway_here

auto vmbr0
iface vmbr0 inet static
        address 10.0.1.1
        netmask 255.255.255.0
        bridge_ports none
        bridge_stp off
        bridge_fd 0

        post-up echo 1 > /proc/sys/net/ipv4/ip_forward
        post-up   iptables -t nat -A POSTROUTING -s '10.0.1.0/24' -o eth0 -j MASQUERADE
        post-down iptables -t nat -D POSTROUTING -s '10.0.1.0/24' -o eth0 -j MASQUERADE

-On all new containers, create eth0 (->vmbr0) and eth1 (->vmbr1) and assign each eth interface a static IP from the appropriate block.

-On all new containers, ensure default route is pointing to 10.0.1.1, if not, then update network config files in container accordingly.

Server Network Topology:

  • Host A (eth0: public IP, vmbr0: 10.0.1.0/24) (eth1/vmbr1: 10.0.2.99/24)

  • Host B (eth0: public IP, vmbr0: 10.0.1.0/24) (eth1/vmbr1: 10.0.2.199/24)

  • Containers (eth0-mapped-to->vmbr0: 10.0.1.[CT#]/24) (eth1-mapped-to->vmbr1: 10.0.2.[CT# if on host-a, else CT#+100]/24)

  • Containers on both hosts can have the same IP in the 10.0.1.x IP block, but not in the 10.0.2.x IP block

Sample Container Configuration:

  • Container # 100 on Host A (eth0->vmbr0: 10.0.1.100/24, gateway: 10.0.1.1) (eth1->vmbr1: 10.0.2.100/24, gateway: 10.0.2.99)

  • Container # 100 on Host B (eth0->vmbr0: 10.0.1.100/24, gateway: 10.0.1.1) (eth1->vmbr1: 10.0.2.200/24, gateway: 10.0.2.199)

  • Container # 101 on Host A (eth0->vmbr0: 10.0.1.101/24, gateway: 10.0.1.1) (eth1->vmbr1: 10.0.2.101/24, gateway: 10.0.2.99)

  • Container # 101 on Host B (eth0->vmbr0: 10.0.1.101/24, gateway: 10.0.1.1) (eth1->vmbr1: 10.0.2.201/24, gateway: 10.0.2.199)

  • Self answering is also encouraged :) – HBruijn Jun 27 '16 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.