tun/tap
Last updated
Was this helpful?
Last updated
Was this helpful?
tun/tap 是 linux 提供的一种用户空间网络的特性。它允许用户空间的程序看见原始网络流量(在 ethernet 或 ip 层),并可以对这些网络流量进行操作。
tun 设备和 tap 设备有什么不同呢?
tun 设备的输出是 ip 数据包。典型的应用场景就是做 ip 通道,比如下图中 OpenVPN 的实现:
Host A 用户空间的程序的数据包被转发到 tun0 设备上,然后被 OpenVPN 读取出来加密,最后从 eth0 出去,到达 Host B。Host B 上的 OpenVPN 从 eth0 读取并解密,并通过 tun0 传输到用户空间的程序。
tap 设备的输出是 ethernet 帧。通常可以用在虚拟网络上。虚拟机通过 tap 设备来读取 ethernet 帧,从而可以在链接层连接到物理网络上。如下图所示:
[Tun/Tap Interface](https://hechao.li/2018/05/21/Tun-Tap-Interface/)
[Tun/Tap interface tutorial](https://backreference.org/2010/03/26/tuntap-interface-tutorial/)