Packet forwarding principle-Layer 2

Source: Internet
Author: User

R1----------SW------------R2
Condition: R1: 192.168.1.1 mac: a R2: 192.168.1.2 mac: B
Sw is a layer-2 Switch
 
When R1 packets are forwarded to R2:
When R1 receives the data packet, it queries the route table of R1. The purpose of querying the route table is to find the data packet from that interface. After finding the interface, what type of frames are encapsulated for the purpose. After the layer-2 frame encapsulation is completed, query the ARP table to find the MAC address of R2. There are two cases:
(1) R1 is found in the ARP table item to complete layer-2 encapsulation and release
(2) If R1 is not found in ARP, the packet is discarded (the second-layer Ethernet frame is discarded), which causes ARP table query on R1. The first packet cannot be pinged. R1 uses mac: a as the source mac, 192.168.1.1 as the source IP, and R2 IP: 192.168.1.2 as the destination IP,
The target mac is a full-F broadcast.
When SW receives an ARP request frame from R1 (receives a layer-2 unicast frame), it opens the frame header to view the source and target mac. It can view its mac table in two cases.
(1) sw receives the arp request frame and looks for its mac table. For example, if it finds the table item and checks the interface of the other party, it restores the frame and does not change the frame sent from R1. Forward from/out interface (two-layer passthrough without changing the source mac)
(2) sw searches for mac tables. If not, a data frame is copied to all interfaces in the corresponding vlan to prevent Frame loss (unknown unicast frame, unknown target mac)
When R2 receives the arp request frame sent from sw, it uses its ip address: 192.168.1.2 as the source ip address, uses mac: B as the source mac address of the outbound interface, and sends an arp response frame to R1, an arp table entry with R1,
When sw receives the arp response frame sent by R2, it will send it to R1 without changing. After R1 receives the response frame, it establishes an arp table entry with R2,
R1 then sends the second icmp echo R2, R2 will respond to R1, and ping is successful.


Author: "Wang bozhi's blog"

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.