Menu Close

Creating OpenVZ in a Centos 6

This tutorial is running under a vps with the following :

  • Memory 2 GB
  • Disk Space 20 GB
  • 4 Cpu core
  • Virtualization KVM
  • Operating System CentOS 6 64bit
  • 1 IPv4
  • /64 IPv6 tunneled from HE

The basic idea is to be able to create an OpenVZ VM inside a KVM VPS.
VM connection to the internet is using NAT trough the eth0 of the KVM VPS, so the OpenVZ VM have direct access to the internet.
Connection from the internet to the OpenVZ VM using port forwarding, which set by IPTABLES.
This tutorial is based from :


Installing basic webserver

Preparing OpenVZ Repository
Add the following repository from OpenVZ to Centos 6

Installing OpenVZ Kernel

Modifying sysctl.conf

Add the following line :

Activate the modification

Modifying the vz.conf

Find the following line, and change the value to “all”

Disable SELINUX in Centos

Find SELINUX line, and change the value to “disabled”

Installing OpenVZ Web Panel for managing the OpenVZ

Wait until installation complete, and you will see something like http://ip.address.of.vps:3000.
Setting iptables
Next, we make some modification to permit acl for port 3000 in the iptables

Add the following lines :

Restart the iptables :

Installing OS template for the OpenVZ

Download all the OS you need here

Example :

Restart your Centos server

Verify that the KVM VPS is using the new OpenVZ kernel

Managing trough OpenVZ Web Panel

Default username is admin, default password is admin.  By using OpenVZ Web Panel, we can add manage the VM, such creation, editing setting, deletion, etc.
Adding IP Pools to the VM
From the OpenVZ Web Panel, click on the left side, and add the IP Pools, since we only have 1 IPv4, we need to add the private IP to the VM, for example – or –
Next, click on the left side, on the localhost, create your first VM, with the veid for example 101, choose the OS template, assign the private IP to the VM, set the disk space, memory, etc.
How to provide access for container to the internet
To give internet access for container to the internet, we need to set IPTABLES with SNAT to the VM. Here, our KVM VPS is using eth0 with the IP address for example
We can set SNAT for each VM, but for the fastest way, lets set SNAT for each IP :

ip_address is the vps IP address, so it would be :



  1. Kurnia Ramadhan

    Kang, saya ada trouble untuk forwarding. Saya baru sukses untuk forwarding SSH ke IP lokal menggunakan port tertentu atau forwarding port 80 ke IP lokal untuk web akses. Saya menggunakan HAproxy.
    Masalahnya, sampai saat ini saya belum menemukan cara untuk gabungin keduanya (SSH dan Web forward) di HAProxy nya seperti yang dilakukan Anthony di LES. Punya solusinya gak kang hehehe

    • Erawan Arif Nugroho

      Maaf telat balasnya mas, hehe baru mudik lebaran siang ini, jadi baru ada sinyal.
      Jadi maunya kayak gini mas?

      Setingannya jadi bikin dua rules di IPTABLES untuk masing-masing port forwardnya.
      Contoh iptables saya :

      Tapi semua port tadi sebenarnya bebas mau dipakai untuk apa saja 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *