I'm using ip tuntap
to create a tap interface, like this:
$ sudo ip tuntap add mode tap tap0
Afterwards, I set the interface up and address it with the common IP commands. I can see then my interface up and addressed with a simple ifconfig
.
Now, I was told by a teacher that by creating a tap interface (named tap0 in that case), I would find a /dev/net/tap0
node, and that I would be able to write in it or to read it. However, I can't find it. I "just" have a /dev/net/tun
.
Do I have to deal with this tun node, or am I supposed to really have a tap0 node?
TUN/TAP devices are virtual interfaces used by VPN clients to establish virtual instances of physical networking connections.
TAP, namely network TAP, simulates a link layer device and operates in layer 2 carrying Ethernet frames. TUN is used with routing. TAP can be used to create a user space network bridge. Packets sent by an operating system via a TUN/TAP device are delivered to a user space program which attaches itself to the device.
To put the matter more simply, the TUN/TAP driver creates a virtual network interface on your Linux box. This interface works just like any other; you can assign IP addresses, route to it, and so on. But when you send traffic to that interface, the traffic is routed to your program instead of to a real network.
Tap interfaces are special software entities which tell the Linux bridge to forward Ethernet frames as it is. In other words, the virtual machines connected to tap interfaces will be able to receive raw Ethernet frames.
It's been a long time since the question was asked, but I thought it would be a good idea to post an actual answer for future reference.
Tap interfaces, as well as tun interfaces, are virtual interfaces provided by the in-kernel TUN/TAP device driver. The only interface this driver provides initially is the character device /dev/net/tun
mentioned in the question.
By issuing:
$ sudo ip tuntap add mode tap tap0
we instruct ip tuntap
to create a network interface named tap0
, which is accomplished using the proper ioctl(2)
calls on the aforementioned device file /dev/net/tun
to talk to the underlying TUN/TAP device driver, as we can observe in ip tuntap
's source code.
One of these ioctl(2)
calls (the one with TUNSETIFF
option, which is called first) returns a file descriptor associated with the new virtual interface that was created and can be used by processes.
Summing it up:
Do I have to deal with this tun node, or am I supposed to really have a tap0 node?
The /dev/net/tun
device file is only used as a starting point to create both tap and tun interfaces, by userspace utilities like iproute2
. In the context of this question, there's no need to deal with it as ip tuntap
does this job for us.
Any extra /dev/net/tap0
device files are not needed or expected to be created for the processes to use the tap interfaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With