Skip to content

Creating a Virtual Network Interface in Linux

A TUN/TAP interface is useful for testing network software, VPN-style data paths, and virtual Ethernet configurations.

Prepare the tools

Install tunctl:

sudo apt-get install uml-utilities

Check that the kernel has TUN support:

modinfo tun
zcat /proc/config.gz | grep TUN

Method 1: Create a TAP interface with tunctl

tunctl -t tap0
ifconfig tap0 192.168.0.1 netmask 255.255.255.0 promisc

Creating a TAP device with tunctl

Method 2: Use ip tuntap

The ip command can also manage TUN/TAP interfaces:

ip tuntap add dev tap3 mode tap
ifconfig tap3 192.168.9.1 netmask 255.255.255.0 promisc

Creating a TAP device with ip tuntap

Run ip tuntap help to see supported modes and options:

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

Installing tunctl from Source

Install from the distribution package when possible:

apt install uml-utilities

To build it from source:

git clone https://github.com/gooselinux/tunctl.git
cd tunctl

# For cross-compilation, set the desired compiler in the Makefile:
# export CC=<cross-compiler>
#
# For a static binary:
# make LDFLAGS="-static"

make
./tunctl --help

Example run:

./tunctl -t tap7
ifconfig tap7 192.168.80.1 netmask 255.255.255.0 promisc