The Hidden Blog

As it turns out, I do have a hostname.

Running OpenVPN with OpenVZ

Published on February 6, 2014

Just filing this away for future reference.

If you want to run OpenVPN within a OpenVZ container you’ll have to setup the iptables rules for the correct network interface (You don’t say!). Most likely it’s called venet0. You can double check this with ifconfig as root or just

ifconfig -a | sed 's/[ \t].*//;/^\(lo\|\)$/d'

to get a list of network interfaces. The proper iptables rules should look like this:

iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -s -j ACCEPT
iptables -A FORWARD -j REJECT
iptables -t nat -A POSTROUTING -s -o venet0 -j MASQUERADE
iptables -A INPUT -i tun+ -j ACCEPT
iptables -A FORWARD -i tun+ -j ACCEPT
iptables -A INPUT -i tap+ -j ACCEPT
iptables -A FORWARD -i tap+ -j ACCEPT

Don’t forget to add them to your /etc/rc.local file to make them persistent across reboots.

The End.