Creating tap/tun devices with IP tuntap and tunctl as detailed in Linux network tools


This article was first published in my public number.CloudDeveloper(ID: cloud_dev)Focus on dry goods sharing. There are a lot of books and videos in the number. Backstage reply「1024」You can get it. Welcome your attention. Two-dimensional code can be scanned at the end.

In the previous article, we have introduced the basic principles of tap/tun, and this article will show you how to use tools.tunctlandip tuntapTo create and use tap/tun devices.



First of allcentosInstallation in Environmenttunctl

[[email protected] ~]# vim /etc/yum.repos.d/nux-misc.repo

name=Nux Misc

ubuntuyesapt-get install uml-utilities

man tunctlSeetunctlThe manual is used as follows:

tunctl [ OPTIONS ] [ -u owner ] [-g group] [ -t device-name ]
  • – The u parameter specifies the user name, indicating that the interface is only controlled by the user, and that what happens to the interface does not affect the interface of the system.
  • – G Specifies a set of users
  • – t specifies the tap / Tun device name to create.


  • – B Simple Print Created Interface Name
  • – n Create Tun devices
  • – P creates a tap device, which is created by default
  • – F tun-clone-device specifies the file name corresponding to the Tun device by default/dev/net/tunSome systems are/dev/misc/net/tun
  • – D interfacename deletes the specified interface


Common usage:

Create tap interface by default:


The above is equivalent totunctl -p

For usersuserCreate a tap interface:

# tunctl -u user

Create Tun interface:

tunctl -n

Configure IP for the interface and enable:

# ifconfig tap0 up

Add routing to the interface:

# route add -host dev tap0

Delete interface:

# tunctl -d tap0

ip tuntap


Command line inputip helpSeeipIs the command supported?tuntapTools, if supported, will be displayedtuntapOptions:

[[email protected] ~]# ip help
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
       ip [ -force ] -batch filename
where  OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable |
                   tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm |
                   netns | l2tp | tcp_metrics | token }

Upgrade or download the latest if not supportediproute2Toolkit, or use the one described abovetunctlTools.


inputip tuntap helpView the Detailed Use Commands:

[[email protected] ~]# ip tuntap help
Usage: ip tuntap { add | del } [ dev PHYS_DEV ]
          [ mode { tun | tap } ] [ user USER ] [ group GROUP ]
          [ one_queue ] [ pi ] [ vnet_hdr ] [ multi_queue ]

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

Common usage:

Create tap/tun devices:

IP tuntap add dev tap0 mod tap # create tap 
IP tuntap add dev tun0 mod Tun # create Tun

Delete tap/tun devices:

IP tuntap del dev tap0 mod tap # delete tap 
IP tuntap del dev tun0 mod Tun # delete Tun

PS: userandgroupParameters andtunctlThe – U and – G parameters are the same.

We recommend using the above two tools.ip tuntapOne is becauseiproute2More complete updates have gradually replaced some of the older tools. Another reason is thattunctlIn someDebianClass is not fully supported on the system.


tunctlandip tuntapCommon usage.

More recommendedip tuntapTools.

My Public NumberCloudDeveloper(ID: cloud_dev)There are a lot of books and videos in the number. Backstage reply「1024」You can get it. The content you share includes but is not limited to cloud computing virtualization, container, OpenStack, K8S, fog computing, network, tools, SDN, OVS, DPDK, Linux, Go, Python, C/C++ programming technology and so on. Welcome your attention.

Creating tap/tun devices with IP tuntap and tunctl as detailed in Linux network tools