When it comes to the MAC address table, we have to talk about the working principle of the switch, because the switch forwards data frames according to the MAC address table. There is a table in the switch that records the correspondence between the MAC address of the LAN host and the interface of the switch. The switch is responsible for transmitting data frames to the designated host according to this table.

How switches work

After the switch receives the data frame, it first records the source MAC address and the corresponding interface in the data frame to the MAC table, and then checks whether there is information about the target MAC address in the data frame in its own MAC table. The data frame will be sent out according to the corresponding interface recorded in the MAC table (that is, unicast). If not, the data frame will be sent out from the non-accepting interface (that is, broadcast).

As shown below: Explain in detail the process of the switch to transmit data frames

1) Host A will send a data frame with the source MAC address as itself and the destination MAC address as host B to the switch.

2) After receiving the data frame, the switch first records the source MAC address and the corresponding interface (the interface is f 0/1) in the data frame into the MAC address table.

3) Then the switch will check whether there is information about the target MAC address in the data frame in its MAC address table. If so, it will be sent from the interface recorded in the MAC address table. If not, the data frame will be sent from the non- All interfaces of the receiving interface are sent out (ie, except the f 0/1 interface).

4) At this time, all hosts on the LAN will receive the data frame, but only host B will respond to the broadcast when it receives the data frame, and respond with a data frame, which includes the MAC address of host B.

5) When the switch receives the data frame responded by host B, it will also record the source MAC address in the data frame (that is, the MAC address of host B). The records in the address table are unicast.

As shown in the figure below: When multiple switches are interconnected in the LAN, how is the MAC address table of the switches recorded?

1) Host A sends a data frame with a source MAC address of itself and a destination MAC address of host C to the switch

2) After switch 1 receives the data frame, it will learn the source MAC address, check the MAC address table, and find that there is no record of the target MAC address, then broadcast the data frame, and both host B and switch 2 will receive the data frame .

3) After the switch 2 receives the data frame, it will also record the source MAC address and the corresponding interface in the data frame into the MAC address table, and check its own MAC address table. If it finds that there is no record of the target MAC address, it will broadcast this data frame.

4) After the host C receives the data frame, it will respond to the data frame and reply a data frame with the source MAC address as its own. At this time, both switch 1 and switch 1 will record the MAC address of host C into their own MAC address table. , and send this data frame to host A in the form of unicast.

5) At this time, the communication between host A and host C is to transmit data frames in the form of unicast, and the communication between host B and host C is the same as the above process, so the MAC address table of switch 2 records the MAC address of host A and host B. The addresses all correspond to interface f 0/1.

Summary: As can be seen from the above two figures, the switch has the function of dynamically learning the source MAC address, and one interface of the switch can correspond to multiple MAC addresses, but one MAC address can only correspond to one interface.

Note: The MAC address dynamically learned by the switch is only valid for 300S by default. If there is no communication with the recorded MAC address within 300S, the record will be deleted.

 


2. Detailed ARP cache table

We have explained the working principle of the switch above, and we know that the switch communicates through the MAC address, but how do we obtain the MAC address of the target host? At this time, we need to use the ARP protocol. There is an ARP table in each host, which records the correspondence between the host's IP address and MAC address.

ARP protocol: ARP protocol is a protocol working at the network layer, which is responsible for resolving IP addresses to MAC addresses.

As shown below: Explain in detail the working principle of ARP.

1) If host A wants to send data to host B, host A will first check its own ARP cache table to see if there is a correspondence between the IP address and MAC address of host B. If so, it will use the MAC address of host B as the The source MAC address is encapsulated into the data frame. If not, host A will send an ARP request message, the destination IP address of the request is the IP address of host B, the destination MAC address is the broadcast frame of the MAC address (ie FF-FF-FF-FF-FF-FF), the source The IP address and MAC address are the IP address and MAC address of host A.

2) After the switch receives the data frame, it finds that the data frame is a broadcast frame, so it will send the data frame from all non-receiving interfaces.

3) When host B receives the data frame, it will check whether the IP address is its own, record the correspondence between the IP address and MAC address of host A in its own ARP cache table, and send an ARP reply at the same time. This includes its own MAC address.

4) After receiving the data frame of the response, the host A records the correspondence between the IP address and the MAC address of the host B in its own ARP cache table. At this point, the switch has learned the MAC addresses of host A and host B.

 


Detailed routing table

The router is responsible for the communication between different networks. It is an important device in today's network. It can be said that there is no Internet today without the router. There is also a table in the router. This table is called the routing table, which records the information to different network segments. The information in the routing table is divided into directly connected routes and non-directly connected routes.

Directly connected route: It is a network segment directly connected to the router interface, which is automatically generated by the router.

Non-directly connected route: It is a network segment that is not directly connected to the router interface. This record needs to be manually added or dynamic routing is used.

Some of the entries recorded in the routing table need to be added manually (called static routing), and some are acquired dynamically by testing (called dynamic routing). Directly connected routes are static routes.

Routers work at the network layer and can identify logical addresses at the network layer. When an interface of a router receives a packet, the router reads the network portion of the logical address of the corresponding destination in the packet, and then looks it up in the routing table. If the routing entry of the destination address is found in the routing table, the packet will be forwarded to the corresponding interface of the router. If the routing entry of the destination address is not found in the routing table, then, if the route is configured with a default route, the configuration of the default route will be forwarded. to the corresponding interface of the router; if no default route is configured, the packet will be discarded and the unreachable information will be returned. This is the process of data routing.

As shown below: a detailed introduction to the working principle of the router

1) HostA encapsulates the message from the upper layer into an IP data packet at the network layer, where the source IP address is itself, and the destination IP address is HostB. Operation, it is concluded that the destination address is not the same network segment as the local machine, so the data packets sent by HostB need to be forwarded by gateway route A.

2) HostA obtains the MAC address of the E0 interface of gateway route A through an ARP request, and encapsulates the MAC address of the router E0 interface into the destination MAC address at the link layer, and the source MAC address is itself.

3) Router A can receive the data frame from E0, remove the encapsulation of the data link layer, and check whether there is an entry matching the target IP address network segment (ie the network segment of 192.168.2.2) in the routing table, according to the route The data recorded on the 192.168.2.0 network segment in the table should be sent to the next hop address 10.1.1.2, so the data is re-encapsulated on the E1 interface of router A. At this time, the source MAC address is the MAC address of the E1 interface of router A. The destination MAC address is the MAC address of the E1 interface of router 2.

4) Route B receives the data frame from the E1 port, and also removes the encapsulation of the data link layer, detects the target IP address, and matches it with the routing table. At this time, it is found that the network segment of the target address is just its own E0 port. On the directly connected network segment, Router B learns the MAC address of Host B through ARP broadcast. At this time, the data packet is re-encapsulated on the E0 interface of Router B. The source MAC address is the MAC address of the E0 interface of Router B, and the destination MAC address is that of Host B. MAC address. After the encapsulation is completed, it is directly sent to HostB from the E0 interface of the router.

5) Only then will HostB receive the data sent from HostA.

Summary: Routing tables are responsible for recording the path from one network to another, so routers work according to routing tables.

 

reference

[1] http://dengqi.blog.51cto.com/5685776/1223132