A common problem I encounter is trying to use OpenVPN on Linux containers hosted using LXC. LXC containers are a great, low resource way to virtualise things but need some extra setup for OpenVPN. Typically you get an error that looks something like:

 ERROR: Cannot open TUN/TAP dev /dev/net/tun: No such file or directory

Step 1

On the host machine we need to add a few lines to the configuration file for the container. The config file is typtically located at ‘/var/lib/lxc/[CONTAINER NAME]/config

Add the below lines to the bottom of this file then stop and start the container to take effect:

## for openvpn
lxc.mount.entry = /dev/net dev/net none bind,create=dir
lxc.cgroup.devices.allow = c 10:200 rwm

Step 2

Four commands need to be run each time the container starts up, the easiest way to do this is edit /etc/rc.local and add them just before the bottom ‘exit 0’ line.

mkdir /dev/net
mknod /dev/net/tun c 10 200
chmod 666 /dev/net/tun
service openvpn restart

That should do it!

 

References:
https://wiki.archlinux.org/index.php/OpenVPN_(client)_in_Linux_containers
https://serverfault.com/questions/429461/no-tun-device-in-lxc-guest-for-openvpn/509200

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail