Hello everyone, I am Brother Lemon, focusing on sharing programming knowledge.

Hello everyone, I am Brother Lemon, focusing on sharing programming knowledge.

Welcome to follow @programmer lemon orange , don’t get lost on the programming road, send the following keywords in private messages to get programming resources:


send 1024 package and download 10 G programming resource learning materials

send 001 get Ali master LeetCode Review notes

send 002 get get Google company programming code specification

send 003 get 10 beautiful resume templates PDF and Word version

send 004 get 100 selected C++ Interview questions and answers word version

send 005 get get Google LeetCode algorithm notes

What is routing? The English name of

router is Router, which is the "route-finding tool". Which way to find? Find the path between various network nodes .

In other words, the router is like express transfer station . Packages will pass through one transfer station and be sent from distant places to near your home, and the same is true for data packets.

A router is a hardware device that connects two networks. It is responsible for the pathfinding function and is the door to the network. Therefore, the router is also called a gateway device (Gateway).

routing table

router, like switch , also has its own small notebook. This routing table records the path between and each network node, and records the data source, corresponding routing entry and next hop. The

routing table is equivalent to the router's navigation . The router only needs to follow the instructions in the routing table. Of course, the premise is that there is a routing entry matching the destination IP address of the packet in the routing table. The routing table will be updated periodically, and will be updated when the network topology changes, so you don’t have to worry about taking the wrong path. The process of

router sending and receiving data packets. When

router sends and receives data packets, it will first check the routing table. If there is a match in the routing table, it will hand the data packet to the next hop. If there is no match, the packet will be discarded directly and the host will be told that the destination is unreachable.

direct connection, static routing, dynamic routing

routing entries can be obtained from many sources, such as direct connection, static routing and dynamic routing.

is directly connected to , that is, the router's is directly adjacent to . The router will get to know the neighbors by itself and then record them.

Of course, you can also tell the router the path of the destination network segment by manually adding , which is static routing , which is suitable for scenarios where the network size is relatively small. But when the network topology changes or the scale expands, the cost of configuration and maintenance will be very high. At this time,

needs to be combined with dynamic routing , so that the router can learn through the dynamic method of . In large networks, this kind of dynamic and static routing combined with is often deployed.

three-layer addressing

two-layer addressing, do you still remember? Layer 2 addressing means that the switch performs addressing at the physical layer based on the MAC address.

Three-layer addressing means that the router performs addressing at the network layer based on the IP address.

Router three-layer addressing process

When the host wants to send data, it will first check whether the destination is in the same network segment as itself. . If is in the same network segment, will let the switch perform Layer 2 forwarding. .

As shown in the figure below, if PC1 wants to send data to PC2, it will be done through the switch.

If they are not in the same network segment, the host will hand the data packet to its own router, and the router will query its own routing table based on the destination IP. If there is a matching entry, it will be handed to the next hop. If not, it will be discarded.

As shown in the figure below, PC1 wants to send data to PC3 and finds that PC3 is not in the same network segment as itself. It will hand the data packet to router A, then forward it to routers B - C according to the entries in the routing table, and finally pass it through switch C. Delivered to PC3.

Principles of path finding

Since the router is responsible for finding the path, all roads lead to Rome, which one is the closest?

Source: Giphy

By default, routing queries follow the longest matching principle , that is, the longer and more accurate the mask is, the router will give priority to that path.

then considers path costs, such as bandwidth, administrative distance, metrics, etc. That is, how much time and money it will cost if we take this route. Most data communication and behaviors are two-way. When considering traffic, you must also pay attention to the round trip of traffic. If you go this way, you have to come back this way. When you come back, there is no way, which is not okay. The behavior of

routing query is one by one . Each router along the way to the target network must have routing information about the target network segment. To put it simply, every time a data packet passes through a router, the router will tell it who the next hop is and which direction it should go .

How to choose a router? The following factors can be considered when selecting a

router: bandwidth requirements/forwarding performance, number of ports, and machine capacity .

For example, if your home has Gigabit broadband, then the router must be a Gigabit router and must meet the Gigabit NAT forwarding performance. By the way, the optical modem provided by the operator comes with its own routing function. If there are no special needs, it is generally sufficient for ordinary households.

In general household scenarios, routing ports are not used too much and can be supplemented through switches. In most commercial scenarios, 4-12 ports are enough. If there are more, I believe most enterprises will choose three-layer switch . The number of

machines is a very important indicator. We generally consider and to send users , as well as the business type of users.

Take UniFi's gateway device as an example: USG can reach 100 concurrencies, which is enough for ordinary households or small and micro businesses; USG-Pro-4 can carry 1,000 machines and can basically meet the needs of small and medium-sized enterprises; if there are still For higher requirements, UDM-Pro can be used.

I am Brother Lemon, focusing on sharing programming knowledge.

Welcome to follow @programmer lemon orange , don’t get lost on the programming road, send the following keywords in private messages to obtain programming resources:


send 1024 package and download 10 G programming resource learning materials

send 001 get Ali master LeetCode review notes

send 002 Get Get Google's programming code specifications

Send 003 Get 10 beautiful resume templates in PDF and Word versions

Send 004 Get 100 selected C++ interview questions and answers in Word version

Send 005 Get Google LeetCode algorithm notes

Source author: YiyiLinux

https://blog.csdn.net/daocaokafei/article/details/124514880