Network devices

1.1 Tun/Tap

TUN (namely network TUNnel) simulates a network layer device and it operates with layer 3 packets like IP packets. TAP (namely network tap) simulates a link layer device and it operates with layer 2 packets like Ethernet frames. TUN is used with routing, while TAP is used for creating a 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. A user-space program may also pass packets into a TUN/TAP device. In this case the TUN/TAP device delivers (or "injects") these packets to the operating-system network stack thus emulating their reception from an external source.

1.2 Usage

  1. ip tuntap
#ip tuntap help
Usage: ip tuntap { add | del | show | list | lst | help } [ dev PHYS_DEV ] 
          [ mode { tun | tap } ] [ user USER ] [ group GROUP ]
          [ one_queue ] [ pi ] [ vnet_hdr ] [ multi_queue ]

Where: USER  := { STRING | NUMBER }
       GROUP := { STRING | NUMBER }
  1. tunctl (man tunctl for help)
#tunctl help
Create: tunctl [-b] [-u owner] [-g group] [-t device-name] [-f tun-clone-device]
Delete: tunctl -d device-name [-f tun-clone-device]

The default tun clone device is /dev/net/tun - some systems use
/dev/misc/net/tun instead

-b will result in brief output (just the device name)

1.3 See also

  1. Tun/Tap interface tutorial
  2. Linux虚拟网络设备之tun/tap

2.1 veth

The veth devices are virtual Ethernet devices. They can act as tunnels between network namespaces to create a bridge to a physical network device in another namespace, but can also be used as standalone network devices.

2.2 Usage

veth devices are always created in interconnected pairs. A pair can
be created using the command:

           # ip link add <p1-name> type veth peer name <p2-name>

In the above, p1-name and p2-name are the names assigned to the two connected end points. Packets transmitted on one device in the pair are immediately received on the other device. When either devices is down the link state of the pair is down.

veth device pairs are useful for combining the network facilities of the kernel together in interesting ways. A particularly interesting use case is to place one end of a veth pair in one network namespace and the other end in another network namespace, thus allowing communication between network namespaces. To do this, one first create the veth device as above and then moves one side of the pair to the other namespace:

# ip link set <p2-name> netns <p2-namespace>

ethtool can be used to find the peer of a veth network interface, using commands something like:

ip link add ve_A type veth peer name ve_B # Create veth pair
ethtool -S ve_A                # Discover interface index of peer
NIC statistics:
          peer_ifindex: 16
ip link | grep '^16:'       # Look up interface
16: ve_B@ve_A: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc ...

2.3 See also

  1. veth - Virtual Ethernet Device
  2. Linux虚拟网络设备之veth
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,483评论 0 10
  • 世界本来很简单 是我们把自己主观意志强加其上,造出了许多烦恼。有时候,事情不像我们想象的那样 当你以单纯的态度去看...
    ticaturn阅读 115评论 0 0
  • 到处走走,看看山川河流,了解民问传信风俗,呼吸新鲜空气,有利身心健康!
    0218b1aa19e1阅读 222评论 0 0
  • 最近,想去儿童医院给孩子做个体检,就下载了"北京儿童医院"手机App。输入孩子的社保卡号后,显示已经被别的手机绑定...
    文风蔚然阅读 4,636评论 0 4
  • 指鹿为马 出自《史记·秦始皇本纪》:“赵高欲为乱,恐群臣不听,乃先设验,持鹿献于二世,曰:‘马也。’二世笑曰:‘丞...
    南山一梦阅读 1,713评论 2 4