[Turn] Linux virtual network infrastructure --tap

Original: https://blog.csdn.net/chengqiuming/article/details/80071073

-------------------------------------------------------------------

Introduce a
Linux talked about tap, and the tun often tied talking about. Both are operating system kernel virtual network devices. tap located on the second floor, tun on the third floor. It should be noted that the device mentioned here is the concept of Linux, not our normal life, said equipment. For example, in life, we often referred to as a one physical router device.
And said apparatus Linux, behind which refers to a data structure similar to the kernel module or device driven like meaning. Like tap / tun this device, its data structures as follows:
struct tun_struct {
char name [. 8]; // device names
unsigned long flags; // distinguish tun and tap device
struct fasync_struct * fasync; // asynchronous notification file structure
wait_queue_head_t read_wait; // wait queue
struct net_device dev; // linux abstracted network device configuration
struct sk_buff_head txq; // network buffer queue
struct net_device_stats stats; // NIC status information structure
};
we see that even the data structure, and TAP tun is a definition, only two are distinguished by a Flag. However, the functions carried behind, the two are still a relatively large difference: tap located on the second network OSI model (data link layer), layer 3 network TUN located.
Benpian only describes the tap.
tap Functionally, the main protocol in the data link layer, the data link layer are:
a point to point protocol (Point-to-Point Protocol)
2 Ethernet (Ethernet)
. 3-level data link protocol (High-Level the Data Link Protocol)
. 4 FR (Frame Relay)
. 5 ATM (Asynchronous Transfer Mode)
, but with only one tap Ethernet protocol (Ethernet) the corresponding agreement. So, tap sometimes called "virtual Ethernet device."

Two real
# To use a Linux command line tap, first have tun module (tun module implements using Linux tun / tap), check follows:
[CentOS the root @ ~] # tun the modinfo
filename: / lib / modules / 3.10.0-327.el7.x86_64 / Kernel / Drivers / NET / tun.ko
Alias: devname: NET / TUN
Alias: Major-char-10-200
License: the GPL
author: (C) 1999-2004 Max Krasnyansky <maxK qualcomm.com @>
Description: Universal TUN / the TAP Device Driver
rhelversion: 7.2
srcversion: B59BCB1255A36FBC7557FC3
The depends:
intree: the Y
vermagic: 3.10.0-327.el7.x86_64 the SMP mod_unload MODVERSIONS
Signer: the CentOS the Linux Kernel Signing Key
sig_key: 79: the AD : 88:. 6A:. 11:. 3C: A0: 22 is: 35: 26 is: 33 is: 6C: 0F: 82: 5B:. 8A: 94: 29:. 6A: B3
sig_hashalgo: SHA256
# when Linux version module having a tun, have look at their already loaded, checked as follows:
[root @ CentOS ~] # lsmod | grep TUN
TUN 27141 1
# If you have already loaded, it will aforementioned "tun ***" line that appears. If not loaded, use the following command to load:
[root @ CentOS ~] # modprobe tun
# When we confirm Linux tun module is loaded later, we need to confirm whether there are Linux operating tun / tap command-line tool tunctl. Enter the following command at the Linux command line
[root @ centos ~] # tunctl help
after # enter this command, if the Linux input, then OK, otherwise the following Web site to install
#https: //blog.csdn.net/lopng/ Article This article was / the Details / 72,821,438
# tunctl have the tun and later, we can create a tap device, the command line is as follows:
[root @ CentOS yum.repos.d] # tunctl -t tap_test
the Set 'tap_test' persistent and. owned by uid 0
# we look just created with the following command TEP (tap_test)
[root @ CentOS yum.repos.d] ip Link List #
1: LO: <LOOPBACK, UP, LOWER_UP> MTU 65536 State qdisc noqueue the MODE UNKNOWN the DEFAULT
Link / the Loopback 00 : 00: 00: 00: 00 : 00 brd 00: 00: 00: 00: 00: 00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
link/ether 08:00:27:12:f4:ac brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT
link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT qlen 500
link/ether 52:54:00:1b:2a:d5 brd ff:ff:ff:ff:ff:ff
5: tap_test: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 500
link/ether 36:c3:5e:1a:6d:f7 brd ff:ff:ff:ff:ff:ff
#我们也可以通过如下命令查看
[root@centos yum.repos.d]# ifconfig -a
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.101 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::a00:27ff:fe12:f4ac prefixlen 64 scopeid 0x20<link>
ether 08:00:27:12:f4:ac txqueuelen 1000 (Ethernet)
RX packets 6364 bytes 8271654 (7.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1770 bytes 172967 (168.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 8 bytes 1104 (1.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 1104 (1.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
tap_test: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 36:c3:5e:1a:6d:f7 txqueuelen 500 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 00:00:00:00:00:00 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0-NIC: the flags = 4098 <BROADCAST, the MULTICAST> MTU 1500
ether 52 is: 54 is: 00:. IB:. 2A: d5 of txqueuelen 500 (Ethernet)
the RX packets 0 bytes 0 (0.0 B)
the RX errors 0 Dropped 0 overruns 0 Frame 0
the TX 0 bytes 0 packets (0.0 B)
TX errors dropped Total 0 0 0 overruns Collisions Carrier 0 0
# output by the above command line, we see that this tap_test not bind IP address. Run the following command to bind IP address:
[root @ CentOS yum.repos.d] # ip addr the Add local 192.168.100.1/24 dev tap_test
# Use the ifconfig -a command again look at
[root @ centos yum.repos. D] # the ifconfig -a
enp0s3: the flags = 4163 <the UP, BROADCAST, the RUNNING, the MULTICAST> 1500 MTU
inet 192.168.0.101 Netmask 255.255.255.0 Broadcast 192.168.0.255
inet6 FE80 :: A00: 27FF: FE12: 64 f4ac the prefixlen ScopeID 0x20 < link>
ether 08:00:27:12:f4:ac txqueuelen 1000 (Ethernet)
RX packets 6500 bytes 8282430 (7.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1845 bytes 183755 (179.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 8 bytes 1104 (1.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 1104 (1.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
tap_test: flags=4098<BROADCAST,MULTICAST> mtu 1500
inet 192.168.100.1 netmask 255.255.255.0 broadcast 0.0.0.0
ether 36:c3:5e:1a:6d:f7 txqueuelen 500 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 00:00:00:00:00:00 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0-nic: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:1b:2a:d5 txqueuelen 500 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
Dropped 0 0 errors overruns the RX Frame 0 0
the TX packets bytes 0 0 (0.0 B)
the TX errors Dropped 0 0 0 overruns Collisions Carrier 0 0
# to this, the device creates a finished tap
----------- -----
Disclaimer: this article is the original article CSDN bloggers "cakincqm", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/chengqiuming/article/details/80071073

Guess you like

Origin www.cnblogs.com/oxspirt/p/12064955.html