Information transfer about two hosts

1. Switch MAC addressing

Forwarding table : LAN host port MAC address and switch port.
Switch : According to the forwarding table, the data frame is forwarded to the designated host port.
Insert picture description here
A sends data to D for the first time:

  • Set the MAC address of the local network card and the MAC address of the target network card and send them to the switch
  • After the switch receives the data, it records the source MAC address
  • The switch checks whether the table has its own destination MAC address , (1) is sent directly from the port recorded in the past (2) is called the frame is not received from all non-transmitted past port (here port 1)
  • For machines that are not the destination MAC , the frame will be ignored, and only host D will respond with a frame
  • At this time, the switch also records the destination MAC address in the switching table

A sends data to D for the second time:
directly find the corresponding port in the exchange table and send the frame.

2. ARP IP/MAC

As can be seen from the above content, we need to know its MAC address if we want to send a message to another host.
So how do we get this data?
ARP table : On each node or host in the topological network, an ARP table is maintained, which records the mapping relationship between the host's IP address (network address) and MAC address (physical address).
ARP protocol (Address Resolution Protocol): It is a network layer protocol that runs on each network node and is responsible for completing the mapping from the host IP address to the MAC address.

process

  • If host A wants to send a data packet to another host B in the same network segment (the nodes connected by the switch are in the same network segment), it is obvious that the user application of A either already knows the IP address of B, or the domain name ( Domain Name, DNS protocol will complete the mapping from host name to IP address , this is not the point),

  • Then host A will first check its own ARP cache table (ARPCache) to see if there is a correspondence between the IP address of host B and its MAC address.

  • If so , the MAC address of the host B network device is directly encapsulated into the data frame as the destination MAC address,
    and all the information required for data frame encapsulation is obtained without further operations. After that, the encapsulation is completed and the data frame is sent to the destination MAC address.

  • If not , host A will send an ARP request message (ARPRequest), the destination IP address of the request is the IP address of host B, and the destination MAC address is the broadcast address of the MAC layer (ie ff:ff:ff:ff:ff:ff ), the source IP address and MAC address are the IP address and MAC address of host A;

  • When the switch receives this data frame, it finds that this frame is a broadcast frame , so it will send this data frame from all ports that are not receiving;

  • All nodes in the same network segment will receive the ARP request packet, and
    the node whose destination IP does not match will directly ignore the request.

  • When host B receives this data frame, it resolves to the same IP address as its own IP address,
    first records the corresponding relationship between host A's IP address and its MAC address in its own ARP cache table, and
    at the same time sends an ARP Reply (ARPResponse), the source MAC address of the reply packet is the MAC address of host B's own network device,

  • The response is forwarded to host A through the switch; host A
    records
    the correspondence between host B's IP address and MAC address in its own ARP cache table after receiving the response data frame .

  • At this time, host A can continue to encapsulate the data frames to be sent to host B, and the switch has also learned the correspondence between the MAC addresses of host A and host B and their ports, and then the data frames sent by host A are forwarded to the host through the switch B.

That is to say, when performing ARP IP resolution, the switch obtains the corresponding relationship of MAC.

The MAC address is always the same when propagated in the same broadcast domain, but when it crosses the broadcast domain (that is, passing through the router), it will change due to re-encapsulation. The source MAC address will become the MAC address of the router's output port, and the destination MAC address It depends on the actual situation of the network topology.

3. The communication process between two hosts

The communication between the two hosts is different under the same network segment and different network segments. The difference is whether or not to be addressed through routing.
(1) Message delivery under the same network segment

  • For
    various applications corresponding to the TCP port on the application layer TCP/IP protocol, if the client wants to access a certain application, it will ask to open the fixed port of the host. The client itself will open a random port greater than 1024 to communicate with the other party's host.

  • Transport layer
    For data segment (Segment), add TCP header (including source port, destination port, sequence number, etc.)
    reasons for segmentation:
    (A): Multiple applications can send data at the same time.
    (B): When a data packet is too large and an error occurs, it needs to be retransmitted, that is, it takes up a lot of time and takes up time. Small data packets have a much smaller impact on the data flow.
    (C): Various network transmission media have their maximum transmission unit limitation, and huge data packets are not allowed to appear on the network.

  • Network layer
    When the transport layer adds a TCP header to the data segment, it sends the data to the network layer for processing. The network layer adds an IP header (including source IP address and destination IP address) to the data packet from the transport layer and encapsulates it into a data packet

  • Data link layer The
    data link layer encapsulates the data frame header in front of the data packet, and encapsulates the check bit at the back of the data packet, thereby encapsulating the data packet into a data frame. (Add the source MAC address and the destination MAC address, if the host does not know the destination MAC address, it wants the switch to send an ARP broadcast to get the destination MAC address)

  • The physical layer
    converts the data frame sent from the logical link layer into an electronic signal that can be transmitted on the physical line, and passes it to the forwarding device switch on the network for processing by the switch.

  • The operation of
    the destination host receiving the data frame When the destination host receives the data frame and compares the destination MAC, if it is sent to itself, it will remove the data frame header and send it to the network layer. The network layer compares the destination IP, if the same, unpack and send To the transport layer, the transport layer compares the destination port again, and after confirming the same, the data segment is removed and sent to the application program for data assembly.

(2) Message delivery under different network segments

  • The application layer data of host A is segmented to the transport layer, marked with TCP header (including source port and destination port), then sent down to the network layer, marked with IP address (including source IP, destination IP), and then sent down to the data At the link layer, data frames (including source MAC and destination MAC) are marked. Since the destination MAC is not known, the MAC address of the gateway (router interface) is marked on the MAC and sent to router A.

  • After router A receives the message, it re-encapsulates the data frame (it knows that it needs to go through router B to send to the host B), so it changes the source MAC address to the MAC address of router A and the destination address to the MAC address of B, (router A performs NAT address Conversion)

  • Router B receives the information from Router A, checks the address, checks the IP, and modifies the MAC. The source MAC is changed to the MAC of Router B, (if host B is in the subnet of Router B), the target MAC is filled in with the MAC of Host B, which is the next step Send information to host B.

  • After the host B receives the data, it breaks the data frame, packet, TCP header, checks its destination address and verification, and re-integrates these data streams, and then passes this data stream to the application layer for processing.

If there is an error, please point it out, thank you!

Reference article
forwarding publication, communication process between two hosts of the switch

Guess you like

Origin blog.csdn.net/weixin_45146520/article/details/114434067