How to create tunnel interface in Linux

19 April 2010 by Fuad NAHDI
Categories: Linux | Tags: , , , , | 1 comment

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 202.182.ab.cd local 203.153.xxx.xx 

Assign an IP address to the tun0 interface:

ifconfig tun0 202.182.ab.254 netmask 255.255.255.252 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.

About Fuad NAHDI

I am a system and network administrator for about 8+ years of experiences. I like to write the documentations when working in office. You can follow me on Twitter (@fuadnahdi) or Google+ (google.com/+FuadNAHDI)

«

»