Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

 

Tun/tap interfaces are software-only interfaces, meaning that they exist only in the kernel and, unlike regular network interfaces, they have no physical hardware component (and so there's no physical "device" connected to them). You can think of a tun/tap interface as a regular network interface that, when the kernel decides that the moment has come to send data "on it", instead sends data to some user-space program that is attached to the interface. When the program attaches to the tun/tap interface, it gets a special file descriptor, reading from which gives it the data that the interface is sending out. In a similar fashion, the program can write to this special descriptor, and the data (which must be properly formatted) will appear as input to the tun/tap interface. To the kernel, it would look like the tun/tap interface is receiving data "from a network device".

The difference between a tap interface and a tun interface is that a tap interface outputs (and must be given) full Ethernet frames, while a tun interface outputs (and must be given) raw IP packets (and no ethernet headers are added by the kernel). Whether an interface functions like a tun interface or like a tap interface is specified with a flag when the interface is created.

Recent versions of iproute2 can create have native tun/tap devicessupport: 

Code Block
languagebash
~$ip tuntap help

Usage: ip tuntap { add | del } [ dev PHYS_DEV ]
           [ mode { tun | tap } ] [ user USER ] [ group GROUP ]

          [ one_queue ] [ pi ] [ vnet_hdr ]

Where: USER  := { STRING | NUMBER }
        GROUP := { STRING | NUMBER }

 

To create a tap (or tun) interface you can follow this simple steps (assuming that the tun interface will be for the openwsn user:

Code Block
languagebash
~$sudo ip tuntap add dev mytun mode tun user openwsn

~$sudo ip link set mytun up

~$sudo ip addr add 10.0.0.1/24 dev mytun
 

References

...

Marek Andreánsky- "Documentation for iproute". Bachelor Thesis. [pdf]: