Deploying a Hardened OpenVPN Server in an LXC Container: A Step-by-Step Guide

Deploying a Hardened OpenVPN Server in an LXC Container: A Step-by-Step Guide

This guide walks you through the process of deploying a hardened OpenVPN server inside a TurnKey LXC container on a Proxmox host. The setup ensures secure access to a personal VPN endpoint using UDP on port 1194, with firewall protections and automated client generation.


Prerequisites

  • Proxmox VE installed on your server.
  • A valid domain name (e.g., vpn.example.com) pointing to your server’s public IP.
  • Basic familiarity with the Linux command line.

Step 1: Prepare the Proxmox Host

Enable TUN/TAP in the LXC Profile

Create the TUN device:


Step 2: Deploy TurnKey OpenVPN LXC Container

Download and Create Container

Upgrade Container

  • install and configure the tools you consider necessary

Update the container config at /etc/pve/lxc/<CTID>.conf:


Step 3: Configure Networking and Security

Configure static ip address

Disable IPv6

Configure iptables

Edit /etc/iptables.up.rules:


Step 4: Configure OpenVPN in the Container

Initialize and Generate PKI

Update OpenVPN Config

Edit /etc/openvpn/server.conf:

Restart OpenVPN:


Step 5: Configure Host Firewall


Step 6: Create VPN Users

Find generated .ovpn files in /etc/openvpn/clients and distribute them securely.


Step 7: Connect from Client

Transfer .ovpn to client and test:

Check logs for successful TLS handshake.


Troubleshooting

  • TLS Errors: Confirm matching ta.key on client and server.
  • Packet Drops: Ensure TUN is active and firewall allows UDP 1194.
  • Duplicate Clients: Use unique certs per client.
  • Replay Errors: Try increasing replay-window size or validate system clocks.

You now have a hardened OpenVPN server running in an LXC container, with secure key management, firewall protection, and automated client provisioning. Perfect for personal VPN or remote secure access.

Leave a Reply

WordPress Appliance - Powered by TurnKey Linux