A detailed description of basic network equipment on Linux

Source: Internet
Author: User
Tags network function

Introduction to Linux Abstract network devices

Similar to disk devices, Linux users want to use the network function, can not be done by direct operation of hardware, but need to directly or indirectly operate a Linux for our abstraction of the device, both common Linux network equipment to complete. A common situation is that the system is equipped with a hardware network card, Linux in the system for it to generate a network device instance, such as eth0, the user needs to issue a command to eth0 to configure or use it. More hardware will bring more instances of the device, and virtual hardware will bring more instances of the device. With the development of network technology and virtualization technology, more advanced network devices have been added to Linux, which makes the situation more complicated. In the following sections, we will analyze the various types of Linux network device abstractions that are commonly used in virtualization technologies: Bridge, 802.1.Q VLAN device, VETH, TAP, and explain in detail how to use them with Route table, IP table in Linux Simply create a local virtual network.

Bridge

bridge (bridge) is a device used on Linux for TCP/IP Layer two protocol switching, similar to the real-world switch function. Bridge device instances can be connected to other network device instances on Linux, both attach a slave device, similar to connecting a network cable between a real-world switch and a user terminal. When data arrives, Bridge broadcasts, forwards, and discards the MAC information in the message.

,bridge are mainly implemented in the kernel. When a slave device is attach to Bridge, the port of the real-world switch is plugged into a network cable with a terminal attached. At this point in the kernel program, Netdev_rx_handler_register () is called, and a callback function to accept the data is registered. This function is called every time the data is received from the device to forward the data to Bridge. When bridge receives this data, Br_handle_frame () is called to perform a similar process to the real-world switch: Judging the category of the package (broadcast/single point), locating the internal MAC port mapping table, locating the target port number, forwarding the data to the destination port, or discarding it, Automatically update the internal MAC port mapping table for self-learning.

There is a difference between Bridge and the two-layer switch in the real world, which is shown on the left side of the diagram: data is sent directly to Bridge instead of being accepted from a port. This situation can be seen as bridge itself has a MAC can actively send messages, or bridge comes with a hidden port and the host Linux system automatically connected, Linux program can directly from this port to the other port on the Bridge to send data. So when a Bridge has a network device, such as Bridge0 joined Eth0, in fact Bridge0 has two valid MAC address, one is BRIDGE0, one is eth0, they can communicate with each other. The interesting thing about this is that Bridge can set the IP address. Typically, the IP address is the content of the three layer protocol and should not appear on the two-tier device Bridge. But Linux Bridge is a generic network device abstraction, as long as the network device can set the IP address. When a BRIDGE0 has an IP, Linux can be routed through the routing table or IP table rules in the three layer positioning BRIDGE0, this time equivalent to Linux has another hidden virtual network card and Bridge of the hidden port connected, this network card is called BRIDGE0 General network Device, IP can be regarded as the network card. When data that conforms to this IP arrives at BRIDGE0, the kernel stack considers that it has received a packet of data that is intended to be native, at which point the application can receive it via the Socket. A better contrast example is the real-world lead-in switch device, which also has a hidden MAC address that is used by the three layer protocol handlers and hypervisor in the device. The three layer protocol handler in the device corresponds to a three layer protocol handler for the generic network device named BRIDGE0, which is the host Linux Kernel protocol stack program. The management program in the device corresponds to the application in the BRIDGE0 host Linux system.

bridge currently has a limitation: when a device is attach to Bridge, the IP of that device becomes invalid, and Linux no longer uses that IP to accept data at layer three. For example, if the eth0 original IP is 192.168.1.2, if you receive a destination address that is 192.168.1.2 data, the Linux application can receive it through the Socket operation. When eth0 is attach to a bridge0, the application cannot accept the above data, although Eth0 's IP is still there. IP 192.168.1.2 should be given to bridge0 at this time.

Another thing to note is the direction of the data flow. For a device to be attach to bridge, only when it receives data, the packet data will be forwarded to bridge to complete the subsequent operations such as table-check broadcast. When the request is a send type, the data is not forwarded to Bridge and it looks for the next send exit. Users often ignore this when they configure the network and cause network failures.


A detailed description of basic network equipment on Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.