How to install a DHCP server (or VPN) in an OpenVZ VPS (Linux)

When installing a DHCP server or another service in an OpenVZ VPS (container) it’s mandatory that the network interface connects directly to the network instead of being routed through a virtual network interface.

OpenVZ can use two different kind of network interfaces in a VPS, called venet or just eth.

The differences of these interfaces can be found on the OpenVZ wiki: http://wiki.openvz.org/Differences_between_venet_and_veth

The key issue here is to connect the physical Ethernet device with the Ethernet device in the container (VPS), since eg. a DHCP needs broadcast to supply an IP-address and a VPN server needs a MAC address for proxy-arping. Here’s the setup:

Basically what would be desired is to have a direct connection to the interface which can be established by bridging.

First of all you need to install bridging-utilities. This can be done eg. on Debian by using APT:

# apt-get install bridge-utils

Then we have to create a bridge on the HN (hardware-node; that is where the containers reside on):

HN # brctl addbr vzbr0

In this case, we name the bridge vzbr0, you can use your own off course.

Create a eth0 in the container you want to connect to where <VEID> stands for your container ID:

HN # vzctl set <VEID> –netif_add eth0,,,,vzbr0 –save

This will create an eth0 device in the specified container (VEID) and add a MAC address to it. On the host this will create veth<veid>.0 device.

Add the veth device to your bridge:

HN # brctl addif vzbr0 <VEID>

You can list the devices connected to your bridge by:

HN # brctl show

Output will be something like this:

Next you will add your physical network device (eth0) from the hardware-node to the bridge. Pay attention; if you configure this from a ssh connection, you’ll be losing your connection. Best is to do it from the console.

HN # brctl addif vzbr0 eth0

Remove the IP-address from your eth0 device:

HN # ifconfig eth 0

And add it to your bridge:

HN # ifconfig vzbr0 <IP-address>

You can configure the IP-address of the eth0 inside the container as you like. Keep your routes in mind on the hardware node and in the container.

Use the vzbr0 device as where it eth0. Be mindful to adjust your persisted network configuration, else all will be gone when you restart your server!

If you have any questions please feel free to drop a comment!

 

 

 

 

Tags: , , ,

About Esmé