How to create tunnel interface in Linux

This tutorial will show you on how to create a tunnel interface in Linux (Slackware, Centos, Debian, Ubuntu, Fedora, Redhat, etc)

To create a tunnel interface, you need to load/activate the ‘tun’ module first because it is unloaded/inactive by default. To activate it use ‘modprobe’ command as below:

modprobe tun

Check that it has been successfully loaded.

lsmod |grep tun
tun                    12160  0

Now create or add a tunnel interface (tun0) to the system. The syntax command should be as follow:

ip tunnel add tun0 mode ipip remote  local  

For example:

ip tunnel add tun0 mode ipip remote local 

Assign an IP address to the tun0 interface:

ifconfig tun0 202.182.ab.254 netmask pointopoint 202.182.ab.253

Sometime you need to change the MTU of tun0 interface to 1500:

ifconfig tun0 mtu 1500 up

Bring the tun0 interface up:

ip link set tun0 up

That’s all. Now you can try to ping to the point to point ip address on the remote router. You should get replied from the remote router.