Simple understanding of routing


Preface

Routing: The router works at the network layer of the OSI reference model. Its important role is to select the best path for the data packet and finally reach the destination.
In order to increase the network access speed as much as possible, a method is needed to determine the best path from the source host to the destination host, so as to forward data. This is routing technology.


One, routing principle

Insert picture description here

1.1 The working principle of the router

Router: A device capable of forwarding data packets to the correct destination and selecting the best path during the forwarding process.

Working principle: forward data according to the routing table.
Insert picture description here

1.2 Formation of the routing table

Routing table: The routing table is actually a collection of routing entries maintained in the router, and the router makes path selection based on the routing table.

Directly connected network segment: When the IP address of the interface is configured on the router, and the interface status is "up", a directly connected route entry appears in the routing table.

Non-directly connected network segments: Network segments that are not directly connected to the router. Static routing or dynamic routing is required to forward these network segments, which need to be written in the routing table.

Two, static routing and default routing

2.1 Static routing

Insert picture description here

Static routes are fixed routes manually configured by the administrator in the router.

Features of static routing:

1. Manually configured by the administrator, which is one-way

2. Lack of flexibility, but high accuracy

2.2 Default route

The default route is a special static route that only exists with the stub network. Proper use of the default route can reduce the size of the routing table.

ps: What is a peripheral route?
When there is only one path in the network that can reach other networks, it is in the stub network at this time, as shown in the gray circle where route B is located in the above figure.

Third, the encapsulation process of the router forwarding the data packet

Insert picture description here
1. When PC1 wants to send data to PC2, it first sends an ARP request and learns the MAC address of R1. PC1 encapsulates and sends data packets to R1 for the first time, where the source IP address is 192.168.1.2, the destination IP address is 192.168.2.2, the source MAC address is 11-11, and the destination MAC address is 22-22.

2. R1 receives the data packet and performs the first decapsulation to remove the source and destination MAC headers. After seeing the source and destination IP addresses, R1 makes an ARP request and learns the MAC address of R2. Then R1 encapsulates the data packet a second time and sends it to R2. The source IP address is 192.168.1.2, the destination IP address is 192.168.2.2, the source MAC address is 33-33, and the destination MAC address is 44-44.

3. R2 receives the data packet and decapsulates the second data packet. Remove the MAC header and see that the destination IP is 192.168.2.2. Then R2 sends the ARP request and obtains the MAC address of PC2, and then performs the third data packet. The encapsulation of is sent to PC2, the source IP address is 192.168.1.2, the destination IP address is 192.168.2.2, the source MAC address is 55-55, and the destination MAC address is 66-66.

to sum up

The router realizes data packet forwarding by querying the routing table. The
routing table is formed in two ways: static addition and dynamic learning.
Static routing is routing information manually added by the administrator. The
default routing is a special static routing. The
routing of data packets is forwarded three times. Encapsulation and double decapsulation

Guess you like

Origin blog.csdn.net/weixin_55609819/article/details/114787311