<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Yix</id>
	<title>OpenVZ Virtuozzo Containers Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Yix"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/Yix"/>
	<updated>2026-06-13T16:33:38Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=VPN_via_the_TUN/TAP_device&amp;diff=9196</id>
		<title>VPN via the TUN/TAP device</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=VPN_via_the_TUN/TAP_device&amp;diff=9196"/>
		<updated>2010-09-30T18:28:18Z</updated>

		<summary type="html">&lt;p&gt;Yix: /* Granting container an access to TUN/TAP */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This article describes how to use VPN via the TUN/TAP device inside a [[container]].&lt;br /&gt;
&lt;br /&gt;
== Kernel TUN/TAP support ==&lt;br /&gt;
OpenVZ supports VPN inside a container via kernel TUN/TAP module and device.&lt;br /&gt;
To allow container #101 to use the TUN/TAP device the following should be done:&lt;br /&gt;
&lt;br /&gt;
Make sure the '''tun''' module has been already loaded on the [[hardware node]]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# lsmod | grep tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If it is not there, use the following command to load '''tun''' module:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# modprobe tun&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To make sure that '''tun''' module will be automatically loaded on every reboot you can also add it or into /etc/modules.conf (on RHEL see /etc/sysconfig/modules/ directory) or into /etc/sysconfig/vz-scripts/''CTID''.mount. (echo 'modprobe tun' &amp;gt;&amp;gt; /etc/sysconfig/vz-scripts/''CTID''.mount)&lt;br /&gt;
&lt;br /&gt;
== Granting container an access to TUN/TAP ==&lt;br /&gt;
Allow your container to use the tun/tap device by running the following commands on the host node:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --devices c:10:200:rw --save&lt;br /&gt;
 vzctl set 101 --capability net_admin:on --save&lt;br /&gt;
&lt;br /&gt;
And create the character device file inside the container (execute the following on the host node):&lt;br /&gt;
&lt;br /&gt;
 vzctl exec 101 mkdir -p /dev/net&lt;br /&gt;
 vzctl exec 101 mknod /dev/net/tun c 10 200&lt;br /&gt;
 vzctl exec 101 chmod 600 /dev/net/tun&lt;br /&gt;
&lt;br /&gt;
Make vzctl recreate device node on container startup:&lt;br /&gt;
&lt;br /&gt;
 vzctl set 101 --devnodes net/tun:rw --save&lt;br /&gt;
&lt;br /&gt;
== Configuring VPN inside container ==&lt;br /&gt;
After the configuration steps above are done it is possible to use VPN software working with TUN/TAP inside&lt;br /&gt;
container just like on a usual standalone linux box.&lt;br /&gt;
&lt;br /&gt;
The following software can be used for VPN with TUN/TAP:&lt;br /&gt;
* Tinc (http://tinc-vpn.org)&lt;br /&gt;
* OpenVPN (http://openvpn.net)&lt;br /&gt;
* Virtual TUNnel (http://vtun.sourceforge.net)&lt;br /&gt;
&lt;br /&gt;
== Reaching hosts behind VPN container ==&lt;br /&gt;
In order to reach hosts behind VPN container you must configure it to use a VETH interface instead a VENET one, at least with an OpenVPN server.&lt;br /&gt;
&lt;br /&gt;
With a VENET interface you will only reach the VPN container.&lt;br /&gt;
&lt;br /&gt;
To use a VETH device follow this [http://wiki.openvz.org/Veth instructions].&lt;br /&gt;
&lt;br /&gt;
== Tinc problems ==&lt;br /&gt;
&lt;br /&gt;
Using the default venet0:0 interface on the container, tinc seems to have problems as it complains the port 655 is already used on 0.0.0.0.&lt;br /&gt;
&lt;br /&gt;
Netstat shows that the port 655 is available:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@132 / [3]# netstat -l&lt;br /&gt;
Active Internet connections (only servers)&lt;br /&gt;
Proto Recv-Q Send-Q Local Address           Foreign Address         State      &lt;br /&gt;
tcp        0      0 localhost.localdom:8001 *:*                     LISTEN     &lt;br /&gt;
tcp        0      0 *:2223                  *:*                     LISTEN     &lt;br /&gt;
tcp6       0      0 [::]:2223               [::]:*                  LISTEN     &lt;br /&gt;
udp6       0      0 [::]:talk               [::]:*                             &lt;br /&gt;
udp6       0      0 [::]:ntalk              [::]:*                             &lt;br /&gt;
Active UNIX domain sockets (only servers)&lt;br /&gt;
Proto RefCnt Flags       Type       State         I-Node   Path&lt;br /&gt;
unix  2      [ ACC ]     STREAM     LISTENING     4831020  /var/run/uml-utilities/uml_switch.ctl&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Starting the Tincd daemon where it complains that port 655 is not available:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@132 / [4]# tincd -n myvpn&lt;br /&gt;
root@132 / [5]# tail -f /var/log/syslog&lt;br /&gt;
Jul 26 14:08:01 132 /USR/SBIN/CRON[15159]: (root) CMD (   cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.hourly)&lt;br /&gt;
Jul 26 14:37:42 132 -- MARK --&lt;br /&gt;
Jul 26 14:57:42 132 -- MARK --&lt;br /&gt;
Jul 26 15:08:01 132 /USR/SBIN/CRON[15178]: (root) CMD (   cd / &amp;amp;&amp;amp; run-parts --report /etc/cron.hourly)&lt;br /&gt;
Jul 26 15:11:23 132 tinc.myvpn[15139]: Got TERM signal&lt;br /&gt;
Jul 26 15:11:23 132 tinc.myvpn[15139]: Terminating&lt;br /&gt;
Jul 26 15:11:37 132 tinc.myvpn[15191]: tincd 1.0.8 (Aug 14 2007 13:51:23) starting, debug level 0&lt;br /&gt;
Jul 26 15:11:37 132 tinc.myvpn[15191]: /dev/net/tun is a Linux tun/tap device (tun mode)&lt;br /&gt;
Jul 26 15:11:37 132 tinc.myvpn[15191]: Can't bind to 0.0.0.0 port 655/tcp: Address already in use&lt;br /&gt;
Jul 26 15:11:37 132 tinc.myvpn[15191]: Ready&lt;br /&gt;
^C&lt;br /&gt;
root@132 / [6]# &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An echo to Bindv6only (see [http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=440150 discussion here]) seems to resolve the problem:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@132 / [12]# echo 1 &amp;gt; /proc/sys/net/ipv6/bindv6only&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Or put in your /etc/sysctl.conf file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
net.ipv6.bindv6only = 1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then apply the changes with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@132 / [14]# sysctl -p&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Troubleshooting ==&lt;br /&gt;
If NAT is needed within the VE, this error will occur on attempts to use NAT:&lt;br /&gt;
&lt;br /&gt;
 # iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j MASQUERADE&lt;br /&gt;
 iptables v1.4.3.2: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)&lt;br /&gt;
 Perhaps iptables or your kernel needs to be upgraded.&lt;br /&gt;
&lt;br /&gt;
The solution is given here:&lt;br /&gt;
&lt;br /&gt;
 http://kb.parallels.com/en/5228&lt;br /&gt;
&lt;br /&gt;
Also see page 69-70 of:&lt;br /&gt;
&lt;br /&gt;
 http://download.openvz.org/doc/OpenVZ-Users-Guide.pdf&lt;br /&gt;
&lt;br /&gt;
Note that the above steps do not solve the problem if a gentoo VE sits on a Centos HN; it's still an unsolved mystery.&lt;br /&gt;
&lt;br /&gt;
== External links ==&lt;br /&gt;
* [http://vtun.sourceforge.net Virtual TUNnel]&lt;br /&gt;
* [http://openvpn.net OpenVPN]&lt;br /&gt;
* [http://tinc-vpn.org Tinc]&lt;br /&gt;
* [http://openvpn.net/index.php/access-server/howto-openvpn-as/186-how-to-run-access-server-on-a-vps-container.html How to run OpenVPN Access Server in OpenVZ]&lt;br /&gt;
* [http://kb.parallels.com/en/696 Parallels KB#696: Is VPN via the TUN/TAP device supported inside a Container?]&lt;br /&gt;
[[Category: HOWTO]]&lt;br /&gt;
[[Category: Networking]]&lt;/div&gt;</summary>
		<author><name>Yix</name></author>
		
	</entry>
</feed>