How routers forward packets

齐天大圣
齐天大圣Original
2020-12-13 18:44:088934browse

First consider a question, how the router performs addressing. There may be two ways. One is like Gaode Map. After entering the starting point and ending point, several complete routes from the starting point to the ending point will come out. The other is similar to a road sign. It does not indicate the complete route, but it will tell you where the next destination is at different intersections.

The router adopts the second method because the first method does not conform to the actual situation. The network is too complex and huge, and it is impossible for a router to know the topology of all the networks. Even if it really saves the routes of all networks, it is extremely inefficient and requires huge storage. In addition, querying routes will also become extremely inefficient.

So the router will only save the information of the network connected to it. In this way, when a data packet passes through a router, the router will select the next hop address based on the destination address and deliver the data packet. There may be It will be forwarded by more than a dozen routers before a data packet is finally delivered to the destination host.

Routers have their own algorithms for forwarding packets. Let’s take a look at how the router forwards packets:

(1) First, the destination address needs to be extracted from the data packet.

(2) See if it can be delivered directly. That is, whether the network where the destination address is located is directly connected to the router. If connected, it can be delivered directly without being forwarded through other routers. Otherwise, execute 3.

(3) Check whether the routing table has a corresponding specific host route. If so, forward it to the next hop address specified by the specific host route. Otherwise, perform 4.

(4) Check whether there is a general route that matches the rule. If there is, forward it based on the next hop address specified by the general route that matches the rule. Otherwise, go to step 5.

(5) If the routing table in the router has a default route set, forward the packet to the address specified by the default route, otherwise execute 6

(6) to discard the packet. And report the forwarding failure

Recommended: "linux video tutorial"

The above is the detailed content of How routers forward packets. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn