How to Enable/Check TUN/TAP module in VPS(OpenVZ)

TUN/TAP are the virtual-network kernel devices. TUN is the short of network TUNnel and TAP is the short of network tap. The TUN simulates a network layer device and it works with layer 3 packets like IP packets.

TAP simulates a link layer device and it works with layer 2 packets like Ethernet frames. TUN is used with routing and TAP is used for creating a network bridge.

These modules are need to be enabled in VPS for VPN configuration. In this article i will define a simple steps to find out whether TUP/TAP is enabled or disabled on your VPS.

Step 1: Login to your VPS via SSH
Step 2: Run this command:

# cat /dev/net/tun
cat: /dev/net/tun: File descriptor in bad state

The above output should be returned if TUN/TAP is enabled for VPS. If you get any output other than the above it means TUN/TAP is not enabled or has problem with TUN/TAP kernal module.

How to enable TUN/TAP in OpenVZ?

Step 1: Login to Node via SSH
Step 2: Run the below command to find out if tun module is already loaded or not

lsmod | grep tun

If the above command returns a blank output it means the TUN module is not loaded in your Node.

Now Run the below command to load TUN module.

modprobe tun
lsmod | grep tun

Step 3: Enabling TUN/TAP on VPS

To make sure that tun module will be loaded automatically on every reboot you can also add it into

/etc/modules.conf (on RHEL see /etc/sysconfig/modules/ directory)

or into

/etc/sysconfig/vz-scripts/VPSID.mount. (echo ‘modprobe tun’ >> 
/etc/sysconfig/vz-scripts/VPSID.mount)

Now time to allow the container to use the tun/tap device by running the following commands on the host node:

vzctl set 101 --devnodes net/tun:rw --save
vzctl set 101 --devices c:10:200:rw --save
vzctl stop 101
vzctl set 101 --capability net_admin:on --save
vzctl start 101
vzctl exec 101 mkdir -p /dev/net
vzctl exec 101 chmod 600 /dev/net/tun

That’s all we have to do.  You also like to know How To Create OpenVPN Server On CentOS 6.X, Please check that and also Give your opinion below if you experience any issues or to discuss your ideas and experiences.

Leave a Reply