How to easily Enable TUN/TAP on OpenVZ for VPN or Proxy Support

Enabling TUN/TAP on OpenVZ is essential for running VPNs and certain proxy services inside containers. Whether you are setting up OpenVPN, WireGuard, or any tunneling-based solution, TUN/TAP devices must be enabled at the host and container levels. This guide walks you through the process to enable TUN/TAP on OpenVZ safely and effectively.


What is TUN/TAP?

Before diving into the configuration, it’s important to understand what TUN and TAP are:

  • TUN (Network TUNnel): Works at the IP level, typically used with routing applications like OpenVPN.
  • TAP (Network TAP): Operates at the Ethernet level, supporting layer 2 traffic, often used for bridging.

These virtual network kernel drivers allow the creation of network interfaces used by tunneling protocols.


Why Enable TUN/TAP in OpenVZ?

By default, TUN/TAP is disabled in OpenVZ containers for security and resource control. However, VPN software or advanced proxy tools require these interfaces to establish encrypted tunnels or perform network routing. If you’re hosting VPN services for personal use or client needs, enabling TUN/TAP is a critical step in preparing your OpenVZ container.


Prerequisites

Before you proceed, ensure the following:

  • You have root access to the OpenVZ host node.
  • The container is already created and running.
  • Your OpenVZ environment supports TUN/TAP modules.

Step-by-Step: How to Enable TUN/TAP on OpenVZ

Step 1: Verify TUN Module on the Host Node

Ensure that the tun module is loaded on the host:

lsmod | grep tun

If it’s not loaded, run:

modprobe tun

Make sure it’s enabled on boot:

echo "tun" >> /etc/modules

Step 2: Enable TUN/TAP in the Container

You need to modify container settings on the host.

2.1 Stop the Container:

vzctl stop <CTID>

Replace <CTID> with the container ID.

2.2 Set Container Configuration:

Run the following command to allow TUN access:

vzctl set <CTID> --devnodes net/tun:rw --save
vzctl set <CTID> --capability net_admin:on --save
vzctl set <CTID> --devices c:10:200:rw --save
  • --devnodes net/tun:rw
    Grants the container read/write access to the /dev/net/tun device.
  • --capability net_admin:on
    Enables the net_admin capability, which is required to configure network interfaces inside the container.
  • --devices c:10:200:rw
    Provides access to the specific character device used by TUN (major 10, minor 200).

These changes ensure that the container can initialize and use the TUN/TAP device, which is essential for running VPN or proxy services.

2.3 Start the Container:

vzctl start <CTID>

Step 3: Create /dev/net/tun in the Container

Log into the container:

vzctl enter <CTID>

Now, ensure the /dev/net/tun device exists:

mkdir -p /dev/net
mknod /dev/net/tun c 10 200
chmod 600 /dev/net/tun

Troubleshooting TUN/TAP in OpenVZ

  • Issue:Cannot open TUN device inside container.
    • Solution: Check device permissions, module loading, and container capabilities.
  • Issue: Device not found after reboot.
    • Solution: Automate /dev/net/tun creation via container startup scripts or templates.

Security Considerations

While enabling TUN/TAP in OpenVZ containers is necessary for VPNs, it also raises security implications:

  • Containers with TUN access can create tunnels bypassing network restrictions.
  • Only trusted users/clients should be allowed access.
  • Always monitor traffic and limit privileges using firewall rules or custom scripts.

Use Cases After Enabling TUN/TAP

Once TUN/TAP is enabled, you can proceed to:

  • Install OpenVPN server/client within the container.
  • Run WireGuard with proper kernel support.
  • Deploy SOCKS proxies or tunnel-based services for secure remote access.

These use cases are common in hosting environments or self-managed VPS services requiring private, secure connectivity.


Conclusion

Enabling TUN/TAP on OpenVZ for VPN or Proxy support is a straightforward yet vital process for secure tunneling operations. Following the right steps ensures compatibility, security, and functionality. Always test the setup post the enablement and keep security best practices in mind when allowing network-related capabilities in containers. To explore reliable and affordable OpenVZ VPS options, you may check the plans available on Veeble’s website.

Scroll to Top