Detailed explanation of Ethernet protocol


foreword

  Suppose there is such a network topology map:
insert image description here

  In the topology diagram, there are three computers A, B, and C, and they are connected through a router in the middle. At this time, computer A wants to send a piece of data to computer C, so how does the data reach computer C? In other words, how does the router know who A wants to send data to? This is the Ethernet protocol
  to be talked about next , which is divided into two parts: the first is the MAC address, and the second is the Ethernet protocol.


1. MAC address

  MAC address is also known as physical address and hardware address . All computers in the world have unique MAC addresses. We can understand that the MAC address is the ID number of the computer device, through which each computer can be accurately found.
  The MAC address has a total of 48 bits. Since 48 binary numbers such as 0 and 1 are not easy to remember and use, it is converted into 12 hexadecimal numbers to represent (one hexadecimal number is equal to four binary bits).
  So how to check the MAC address of the computer? Proceed as follows.
  Step 1: Press the win+R key on the keyboard at the same time to open the run box.
insert image description here

Step 2: Enter the command cmd   in it and click OK.
insert image description here

Step 3: Enter the black console, enter the command ipconfig/all   in it , and press the Enter key to view the MAC addresses of all physical devices on the machine.
insert image description here

  The 12-digit hexadecimal numbers pointed to by the arrow in the figure above, paired in pairs and connected with a horizontal bar, are MAC addresses (also called physical addresses). The reason why there are two MAC addresses above is because a virtual machine is installed on the blogger's computer. If there are multiple virtual machines, there will be multiple MAC addresses. If it is a laptop, it will also have the MAC address of the wireless network card on it.

2. Ethernet protocol

  • Ethernet (Ethernet) is a widely used local area network technology ;
  • The Ethernet protocol is a protocol at the data link layer ;
  • The data frame transmission of adjacent devices can be completed by using Ethernet ;

1. Ethernet data format

  The Ethernet data format is as follows:
insert image description here

  The first two parts: destination address and source address are the MAC address we just mentioned. The destination address is the MAC address of the host to which the data is sent, and the source address is the MAC address of the host that sends the data. So what does the number 6 under the two addresses mean? As mentioned above, the MAC address has a total of 48 bits, one byte is equal to 8 bits, 48/8=6, and the 6 here actually means 6 bytes. Both the destination MAC address and the source MAC address occupy 6 bytes. The type takes 2 bytes and the final CRC (Cyclic Redundancy Check Code) takes 4 bytes. The frame data inside occupies 46 to 1500 bytes.
  The above is the data format of Ethernet. I will also expand the type for everyone. The type here indicates what protocol type data is used for the frame data to be transmitted.
  For example, if it is IP data at the network layer, the type is 0800, and each number here is a hexadecimal number.
insert image description here
  If the frame data is a request or response of the ARP protocol, then its type is 0806.
insert image description here

  If the frame data is a request or response of the RARP protocol, its type is 8035.
insert image description here

2. MAC address table

  Next, look at the Ethernet MAC address table. The function of the address table is to map the MAC address of each computer to a specific hardware interface, as shown in the figure below.
insert image description here
  It can be seen from the figure above that each MAC address has a corresponding interface, for example, 31-B4-9E-ED-85-CA is mapped to interface 1.
  So where is the MAC address table stored? How to use it? The answer is simple, go back to the network topology map we mentioned at the beginning.
insert image description here

  And the question raised at the beginning: the data in the network reaches computer C from computer A through router E. How does the router know that the data of A is sent to C? Assume that the MAC address table is stored in router E, as shown in the following figure.
insert image description here

  The MAC address of computer A is connected to the E1 hardware interface, computer B is connected to the E2 interface, and computer C is connected to the E3 interface. If A needs to send data to C, let's look at the whole process.

  1. A sends data frames through the network card.
  2. The data frame arrives at the router, and the router takes out the first 6 bytes (as we mentioned just now, the first 6 bytes are the MAC address of the destination machine).
  3. The router matches the MAC address table to find the corresponding network interface. (We know that A needs to be transmitted to C, so the first 6 bytes in the Ethernet data are C's MAC address, router E will match the MAC address table, and find that C's hardware interface is E3).
  4. Finally the router sends the data frame through this network interface.

  This completes the entire process of data being sent from A to C and received, and the MAC address table plays an important role here. This MAC address table is actually owned by the router. Speaking of this, some friends may have doubts: If the MAC address table does not know which hardware interface C is, as shown in the figure below.
insert image description here

  What should we do at this time? Let's take a look at how the router handles this situation. Then in the same way, A sends data to C.

  • Router E checks the MAC address table and finds that there is no information about C.
  • Router E will broadcast A's data packets to ports other than A (that is, E will send A's data to B and C).
  • Then E will receive responses from B and C, and record their MAC addresses and interfaces. After recording it, E will know what the interface corresponding to C is, and then E can accurately send the data to C.

  This is the whole process of how the router does packet processing when it does not know the MAC address mapping.

Guess you like

Origin blog.csdn.net/2201_75641637/article/details/130877620